Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to use a language field stored on the user model directly #78

Open
ricardogsilva opened this issue Nov 20, 2017 · 0 comments

Comments

@ricardogsilva
Copy link

Currently it is not possible to put the language field directly on the user model because the get_default_language() function expects to find it on a related model of the one specified in PINAX_NOTIFICATIONS_LANGUAGE_MODEL. I'm referring to this part of the code:

language = model._default_manager.get(user__id__exact=user.id)

While I understand the reasoning for this, I think it would be useful to also look for the language in the user model directly. Something like:

model = settings.PINAX_NOTIFICATIONS_GET_LANGUAGE_MODEL()
try:
    language = model._default_manager.get(user__id__exact=user.id)
except FieldError:  # maybe we're using custom a user model?
    language = getattr(model, "language", None)

If this is not acceptable, adding FieldError to the tuple of exceptions which are caught would at least allow the function to still complete without error.

This would cater for use cases where the user model has been extended with additional fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant