structure = models.ForeignKey(Structure, on_delete=models.CASCADE, verbose_name=_("Related structure"), blank=True, null=True) objects = models.Manager() check_structure_in_forms = True class Meta: abstract = True verbose_name = _("Related structures") verbose_name_plural = _("Related structure") class UserProfile(StructureRelated): """ A custom user profile """ user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE) class Meta: verbose_name = _("User's profile") verbose_name_plural = _("User's profiles") def __str__(self): return _("Profile for %s") % self.user User.profile = reify(lambda u: UserProfile.objects.get_or_create(user=u)[0])
verbose_name = _(u"Related structures") verbose_name_plural = _(u"Related structure") class UserProfile(StructureRelated): """ A custom user profile """ user = models.OneToOneField(User, unique=True) language = models.CharField(_(u"Language"), max_length=10, choices=settings.LANGUAGES, default=settings.LANGUAGE_CODE) class Meta: verbose_name = _(u"User's profile") verbose_name_plural = _(u"User's profiles") def __unicode__(self): return _("Profile for %s") % self.user User.profile = reify(lambda u: UserProfile.objects.get_or_create(user=u)[0]) @receiver(user_logged_in) def lang(sender, **kwargs): """ Set user's language in session when he logs in. """ lang_code = kwargs['user'].profile.language kwargs['request'].session[LANGUAGE_SESSION_KEY] = lang_code