Skip to content
Snippets Groups Projects

Preserve newsletter content ordering by setting the initial order value in the form

Merged Ghost User requested to merge fix/newsletter-ordering into master
2 files
+ 23
10
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -13,12 +13,17 @@ class NewsletterItemInline(admin.StackedInline):
extra = 0
ordering = ('_order',)
def get_formset(self, request, obj=None, **kwargs):
formset = super().get_formset(request, obj, **kwargs)
if obj is not None:
count = obj.newslettercontent_set.count()
formset.form.declared_fields['order'].initial = count
return formset
class NewsletterEventInline(admin.StackedInline):
class NewsletterEventInline(NewsletterItemInline):
form = NewsletterEventForm
model = NewsletterEvent
extra = 0
ordering = ('_order',)
@admin.register(Newsletter)
Loading