diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-11 19:04:29 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-09-11 19:04:29 +0200 | 
| commit | f9741ae70536851f24318e09bce51086de6bc130 (patch) | |
| tree | 650a11a821b90e90a3742393799f4a9be79eda93 /ishtar_common/models.py | |
| parent | 749dcf5d36a0cecb1649c73e290c4884c74d818e (diff) | |
| download | Ishtar-f9741ae70536851f24318e09bce51086de6bc130.tar.bz2 Ishtar-f9741ae70536851f24318e09bce51086de6bc130.zip | |
Template values: manage find grouping
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 12 | 
1 files changed, 7 insertions, 5 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index f2ebb3c29..ef9a59937 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -54,7 +54,8 @@ from django.contrib.postgres.fields import JSONField  from django.contrib.postgres.search import SearchVectorField, SearchVector  from django.contrib.sites.models import Site  from django.core.cache import cache -from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.core.exceptions import ObjectDoesNotExist, ValidationError, \ +    MultipleObjectsReturned  from django.core.files.uploadedfile import SimpleUploadedFile  from django.core.files import File  from django.core.serializers import serialize @@ -63,7 +64,6 @@ from django.core.validators import validate_slug  from django.db import connection  from django.db.models import Q, Max, Count, F  from django.db.models.signals import post_save, post_delete, m2m_changed -from django.db.models.fields.related import ManyToManyField, ManyToManyRel  from django.db.utils import DatabaseError  from django.template.defaultfilters import slugify  from django.utils.functional import lazy @@ -153,14 +153,16 @@ class ValueGetter(object):          if hasattr(self, "qrcode"):              values['qrcode_path'] = self.qrcode_path          for field_name in get_all_field_names(self): -            if not hasattr(self, field_name) or \ -                    field_name in self.GET_VALUES_EXCLUDE_FIELDS: +            try: +                value = getattr(self, field_name) +            except (AttributeError, MultipleObjectsReturned): +                continue +            if field_name in self.GET_VALUES_EXCLUDE_FIELDS:                  continue              if hasattr(self, "get_values_for_" + field_name):                  values[prefix + field_name] = getattr(                      self, "get_values_for_" + field_name)()              else: -                value = getattr(self, field_name)                  if hasattr(value, 'get_values'):                      values.update(value.get_values(prefix + field_name + '_'))                  else: | 
