mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
Model edit form now reuses save logic
This commit is contained in:
parent
e9fd0abb2f
commit
16ceca0dfe
3 changed files with 25 additions and 15 deletions
|
|
@ -9,6 +9,9 @@
|
|||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
|
||||
{# TODO: combine/refactor this with model_edit_form.html #}
|
||||
|
||||
<button class="btn btn-small" type="submit" name="_addanother">Save and add another</button>
|
||||
<button class="btn btn-small" type="submit" name="_continue">Save and continue editing</button>
|
||||
<button class="btn btn-small btn-success" type="submit" name="_save">Save</button>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@
|
|||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit"/>
|
||||
|
||||
{# TODO: combine/refactor this with model_add_form.html #}
|
||||
|
||||
<button class="btn btn-small" type="submit" name="_addanother">Save and add another</button>
|
||||
<button class="btn btn-small" type="submit" name="_continue">Save and continue editing</button>
|
||||
<button class="btn btn-small btn-success" type="submit" name="_save">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -77,6 +77,20 @@ class AdminModel2Mixin(Admin2Mixin, AccessMixin):
|
|||
return modelform_factory(self.get_model())
|
||||
|
||||
|
||||
class Admin2ModelFormMixin(object):
|
||||
|
||||
def get_success_url(self):
|
||||
if '_continue' in self.request.POST:
|
||||
view_name = admin2_urlname(self, 'update')
|
||||
return reverse(view_name, kwargs={'pk': self.object.pk})
|
||||
|
||||
if '_addanother' in self.request.POST:
|
||||
return reverse(admin2_urlname(self, 'create'))
|
||||
|
||||
# default to index view
|
||||
return reverse(admin2_urlname(self, 'index'))
|
||||
|
||||
|
||||
class IndexView(Admin2Mixin, generic.TemplateView):
|
||||
default_template_name = "index.html"
|
||||
registry = None
|
||||
|
|
@ -107,14 +121,13 @@ class ModelDetailView(AdminModel2Mixin, generic.DetailView):
|
|||
permission_type = 'view'
|
||||
|
||||
|
||||
class ModelEditFormView(AdminModel2Mixin, generic.UpdateView):
|
||||
class ModelEditFormView(AdminModel2Mixin, Admin2ModelFormMixin, generic.UpdateView):
|
||||
form_class = None
|
||||
success_url = "../../"
|
||||
default_template_name = "model_edit_form.html"
|
||||
permission_type = 'change'
|
||||
|
||||
|
||||
class ModelAddFormView(AdminModel2Mixin, generic.CreateView):
|
||||
class ModelAddFormView(AdminModel2Mixin, Admin2ModelFormMixin, generic.CreateView):
|
||||
form_class = None
|
||||
default_template_name = "model_add_form.html"
|
||||
permission_type = 'add'
|
||||
|
|
@ -124,17 +137,6 @@ class ModelAddFormView(AdminModel2Mixin, generic.CreateView):
|
|||
context['model'] = self.get_model()._meta.verbose_name
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
if '_continue' in self.request.POST:
|
||||
view_name = admin2_urlname(self, 'update')
|
||||
return reverse(view_name, kwargs={'pk': self.object.pk})
|
||||
|
||||
if '_addanother' in self.request.POST:
|
||||
return reverse(admin2_urlname(self, 'create'))
|
||||
|
||||
# default to index view
|
||||
return reverse(admin2_urlname(self, 'index'))
|
||||
|
||||
|
||||
class ModelDeleteView(AdminModel2Mixin, generic.DeleteView):
|
||||
success_url = "../../"
|
||||
|
|
|
|||
Loading…
Reference in a new issue