Skip to content

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

Description

@ricardogsilva

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions