From a5f5761b490cd940c5cfe005fe97a64c47515be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Paj=C4=85k?= Date: Thu, 22 Jun 2023 12:51:43 +0200 Subject: [PATCH] Update admin_forms.py Fix Message instance needs to have a primary key --- newsletter/admin_forms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/newsletter/admin_forms.py b/newsletter/admin_forms.py index f3180290..da12ad04 100644 --- a/newsletter/admin_forms.py +++ b/newsletter/admin_forms.py @@ -175,6 +175,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) assert self.instance - next_sortorder = self.instance.get_next_article_sortorder() - for index, form in enumerate(self.extra_forms): - form.initial['sortorder'] = next_sortorder + index * 10 + if self.instance.pk: + next_sortorder = self.instance.get_next_article_sortorder() + for index, form in enumerate(self.extra_forms): + form.initial['sortorder'] = next_sortorder + index * 10