Improve natural key support in the UserOptions model.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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)
|
||||
==================
|
||||
|
||||
15
mayan/apps/user_management/managers.py
Normal file
15
mayan/apps/user_management/managers.py
Normal 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)
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user