stephenmuss / django-ios-notifications

Django iOS Notifications makes it easy to send push notifications to iOS devices
Other
230 stars 72 forks source link

Can I redefine Device Model? #53

Closed alexche8 closed 7 years ago

alexche8 commented 10 years ago

I need to redefine Device Model because devices in our application can't be owned by few users. Change field users = models.ManyToManyField(getattr(settings, 'AUTH_USER_MODEL', 'auth.User'), null=True, blank=True, related_name='ios_devices') to users = models.ForeignKey(getattr(settings, 'AUTH_USER_MODEL', 'auth.User'), null=True, blank=True, related_name='ios_devices') Maybe some settings for default model...

stephenmuss commented 10 years ago

I would be open to entertaining the idea of a flexible device model. Did you have an idea of how you would go about this?

mbargiel commented 10 years ago

Keep in mind that while it´s easier to use a model that has a FK rather than a M2M field, one is strictly more general than the other, that is, you can still tie a device to a single person by not adding multiple users to the M2M field for a given device. But if performance is an issue though, it might be good to consider this change.

Personally, I'd be open for this change. Our own use case was similar to this and it would have bben simpler for us to have this FK instead. I would rename it to "user" instead of "users" though. Such a change needs to be documented as it is a breaking change for anyone who has more than one user tied to a single device and south migrations must be created as well (schema: add user; data: populate user from users; schema: remove users).

Stephen, did you have a use case for multiple users tied to a device that required the M2M field in the model?

As we saw with the User Model, custom models in re-usable apps add a lot of complexity and I don't this a custom device model would add a lot of benefit. Alternatives I recommend is composition (kind of like the Django User Profiles of old, but withought the genericity of the feature) or proxy models.

Le samedi 16 août 2014, Stephen Muss notifications@github.com a écrit :

I would be open to entertaining the idea of a flexible device model. Did you have an idea of how you would go about this?

— Reply to this email directly or view it on GitHub https://github.com/stephenmuss/django-ios-notifications/issues/53#issuecomment-52390386 .

stephenmuss commented 10 years ago

It's been quite a while now I can't remember what the need for an M2M field for users was. To be honest, it seems to me now that a FK user would suffice for the vast majority of use cases. I'm therefore quite open to updating the schema. Since all the changes we have in the pipeline are breaking in any case, I don't think it hurts to include changing the users field to user.