django-addanother
stable
  • How to Install
  • Demo
  • How to Use
  • Edit-related buttons
  • Select2 Integration
  • How it Works
  • Reference
django-addanother
  • Docs »
  • Edit-related buttons
  • Edit on GitHub

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:

  1. Wrap your widget with the AddAnotherEditSelectedWidgetWrapper class, and provide an edit URL in addition to the add URL.
  2. 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.

Next Previous

© Copyright 2015, Jonas Haag, James Pic. Revision 9d13ad5e.

Built with Sphinx using a theme provided by Read the Docs.