Commit b357fcae authored by Luuk Scholten's avatar Luuk Scholten
Browse files

Merge branch 'fix/event-information-field-ordering' into 'master'

Preserve event information field ordering by setting the initial order value in the form

See merge request !388
parents 67a68d96 bf9848c0
......@@ -40,6 +40,13 @@ class RegistrationInformationFieldInline(admin.StackedInline):
radio_fields = {'type': admin.VERTICAL}
def get_formset(self, request, obj=None, **kwargs):
formset = super().get_formset(request, obj, **kwargs)
if obj is not None:
count = obj.registrationinformationfield_set.count()
formset.form.declared_fields['order'].initial = count
return formset
@admin.register(models.Event)
class EventAdmin(DoNextModelAdmin):
......
......@@ -2,12 +2,22 @@ from django import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import get_language
from .models import RegistrationInformationField
from .models import RegistrationInformationField, Event
class RegistrationInformationFieldForm(forms.ModelForm):
order = forms.IntegerField(label=_('order'), initial=0)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
try:
event = self.instance.event
order = event.get_registrationinformationfield_order()
order_value = list(order).index(self.instance.pk)
self.fields['order'].initial = order_value
except Event.DoesNotExist:
pass
class Meta:
fields = '__all__'
model = RegistrationInformationField
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment