Improve natural key support in the UserOptions model.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-09-21 00:07:08 -04:00
parent 923cb3a7f2
commit ef1f011cd5
3 changed files with 21 additions and 0 deletions

View File

@@ -2,6 +2,8 @@
==================
* Database access in data migrations defaults to the 'default' database. Force it to the user selected database instead.
* Don't use a hardcoded database alias for the destination of the database conversion.
* Improve natural key support in the UserOptions model.
3.1.1 (2018-09-18)
==================

View File

@@ -0,0 +1,15 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.db import models
class UserOptionsManager(models.Manager):
def get_by_natural_key(self, user_natural_key):
User = get_user_model()
try:
user = User.objects.get_by_natural_key(user_natural_key)
except User.DoesNotExist:
raise self.model.DoesNotExist
return self.get(user__pk=user.pk)

View File

@@ -4,6 +4,8 @@ from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from .managers import UserOptionsManager
class UserOptions(models.Model):
user = models.OneToOneField(
@@ -15,6 +17,8 @@ class UserOptions(models.Model):
verbose_name=_('Forbid this user from changing their password.')
)
objects = UserOptionsManager()
class Meta:
verbose_name = _('User settings')
verbose_name_plural = _('Users settings')