mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-04-12 19:01:04 +00:00
Refactor duplicate model add/edit forms.
This commit is contained in:
parent
5836a1cb97
commit
b79523c659
3 changed files with 11 additions and 26 deletions
|
|
@ -1,20 +0,0 @@
|
|||
{% extends "admin2/bootstrap/base.html" %}
|
||||
|
||||
{% block title %}Add {{ model }}{% endblock %}
|
||||
|
||||
{% block page_title %}Add {{ model }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<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>
|
||||
</form>
|
||||
|
||||
{% endblock content %}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
{% extends "admin2/bootstrap/base.html" %}
|
||||
|
||||
{% block title %}Change {{ model }}{% endblock %}
|
||||
{% block title %}{{ action }} {{ model }}{% endblock %}
|
||||
|
||||
{% block page_title %}Change {{ model }}{% endblock %}
|
||||
{% block page_title %}{{ action }} {{ model }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
|
@ -12,8 +12,6 @@
|
|||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
|
||||
{# 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>
|
||||
|
|
@ -123,18 +123,25 @@ class ModelDetailView(AdminModel2Mixin, generic.DetailView):
|
|||
|
||||
class ModelEditFormView(AdminModel2Mixin, Admin2ModelFormMixin, generic.UpdateView):
|
||||
form_class = None
|
||||
default_template_name = "model_edit_form.html"
|
||||
default_template_name = "model_update_form.html"
|
||||
permission_type = 'change'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ModelEditFormView, self).get_context_data(**kwargs)
|
||||
context['model'] = self.get_model()._meta.verbose_name
|
||||
context['action'] = "Change"
|
||||
return context
|
||||
|
||||
|
||||
class ModelAddFormView(AdminModel2Mixin, Admin2ModelFormMixin, generic.CreateView):
|
||||
form_class = None
|
||||
default_template_name = "model_add_form.html"
|
||||
default_template_name = "model_update_form.html"
|
||||
permission_type = 'add'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ModelAddFormView, self).get_context_data(**kwargs)
|
||||
context['model'] = self.get_model()._meta.verbose_name
|
||||
context['action'] = "Add"
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue