Fixed the save method of the LocalizedModel data model to find the l10n records only for existing models, to work with Django 4.1.

This commit is contained in:
依瑪貓 2022-12-04 23:01:02 +08:00
parent 4afd072cc5
commit f57162a93c

View File

@ -126,9 +126,12 @@ class LocalizedModel(models.Model):
current_value = getattr(self, name + "_l10n") current_value = getattr(self, name + "_l10n")
if current_value is None or current_value == "": if current_value is None or current_value == "":
setattr(self, name + "_l10n", new_value) setattr(self, name + "_l10n", new_value)
l10n_rec = self._get_l10n_set()\ if self.pk is None:
.filter(name=name, language=language)\ l10n_rec = None
.first() else:
l10n_rec = self._get_l10n_set()\
.filter(name=name, language=language)\
.first()
if l10n_rec is None: if l10n_rec is None:
l10n_to_save.append(self._get_l10n_set().model( l10n_to_save.append(self._get_l10n_set().model(
master=self, name=name, master=self, name=name,