diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-09-16 10:29:22 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:20:58 +0100 |
commit | ec2fc0e18a490634a2da97a16ac94725c3acdc32 (patch) | |
tree | b20ee23a82f76fc63ee99417007d57f310d34ceb /ishtar_common/models_common.py | |
parent | f2f735ed86dd12c37ded45eb0b191b02582c3d08 (diff) | |
download | Ishtar-ec2fc0e18a490634a2da97a16ac94725c3acdc32.tar.bz2 Ishtar-ec2fc0e18a490634a2da97a16ac94725c3acdc32.zip |
Migration to Django 2.2 - fixes
- rel -> remote_field
- to -> model
- default initialization for historical models
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r-- | ishtar_common/models_common.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 66cf0c5e5..196e8a7d7 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -816,9 +816,9 @@ class FullSearch(models.Model): def general_types(cls): for k in get_all_field_names(cls): field = cls._meta.get_field(k) - if not hasattr(field, "rel") or not field.rel: + if not hasattr(field, "remote_field") or not field.remote_field: continue - rel_model = field.rel.to + rel_model = field.remote_field.model if issubclass(rel_model, (GeneralType, HierarchicalType)): yield k @@ -1180,6 +1180,14 @@ class HistoryError(Exception): class HistoricalRecords(BaseHistoricalRecords): + def get_extra_fields(self, model, fields): + extra_fields = super().get_extra_fields(model, fields) + # initialize default empty fields + for key in getattr(model, "HISTORICAL_M2M", []): + extra_fields[key] = "" + extra_fields["documents"] = "" + return extra_fields + def _save_historic( self, manager, @@ -1442,12 +1450,13 @@ class BaseHistorizedItem( setattr(item, k, None) continue try: - val = field.rel.to.objects.get(pk=val) + val = field.remote_field.model.objects.get(pk=val) setattr(item, k, val) except ObjectDoesNotExist: if strict: raise HistoryError( - "The class %s has no pk %d" % (str(field.rel.to), val) + "The class %s has no pk %d" + % (str(field.remote_field.model), val) ) setattr(item, k, None) item.pk = self.pk @@ -2810,7 +2819,7 @@ class GeoItem(models.Model): verbose_name=_("Spatial Reference System"), blank=True, null=True, - on_delete=models.PROTECT + on_delete=models.PROTECT, ) point = models.PointField(_("Point"), blank=True, null=True, dim=3) point_2d = models.PointField(_("Point (2D)"), blank=True, null=True) |