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 | ba023f2d3ef0010d00212134c689416a9de3ff6f (patch) | |
tree | 650a11a821b90e90a3742393799f4a9be79eda93 | |
parent | 6f3f6437a63032a230a16c2b120406a5a9a12b6f (diff) | |
download | Ishtar-ba023f2d3ef0010d00212134c689416a9de3ff6f.tar.bz2 Ishtar-ba023f2d3ef0010d00212134c689416a9de3ff6f.zip |
Template values: manage find grouping
-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: |