Improve natural key handing for the Document, Metadata, DocumentMetadata, DocumentTypeOCRSetting and UserProfileLocale models.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import apps
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.db import models
|
||||
|
||||
@@ -11,3 +12,14 @@ class ErrorLogEntryManager(models.Manager):
|
||||
app_label='common', model_name='ErrorLogEntry'
|
||||
)
|
||||
model.add_to_class('error_logs', GenericRelation(ErrorLogEntry))
|
||||
|
||||
|
||||
class UserLocaleProfileManager(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)
|
||||
|
||||
Reference in New Issue
Block a user