Edit-related buttonsΒΆ
Similarly to add-another buttons (see How to Use), to add edit-related buttons to your widget, proceed with the following steps:
- Wrap your widget with the
AddAnotherEditSelectedWidgetWrapper
class, and provide an edit URL in addition to the add URL. - Make your edit view popup-compatible by having it inherit the
CreatePopupMixin
class.
The edit URL must contain the __fk__
string as a placeholder for the actual object’s primary key. Example:
# forms.py
from django.core.urlresolvers import reverse_lazy
from django_addanother.widgets import AddAnotherEditSelectedWidgetWrapper
class FooForm(forms.ModelForm):
class Meta:
...
widgets = {
'sender': AddAnotherEditSelectedWidgetWrapper(
forms.Select,
reverse_lazy('person_create'),
reverse_lazy('person_update', args=['__fk__']),
)
}
# views.py
from django_addanother.views import UpdatePopupMixin
class PersonUpdate(UpdatePopupMixin, UpdateView):
model = Foo
...
If you need the edit-related button only, but not the add-another, wrap your widget with the EditSelectedWidgetWrapper
class and remove the add URL.