From 7d94609f9b45e187438d200d0fac8012095fc537 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sun, 11 Aug 2019 18:37:04 +0200 Subject: [PATCH] Add shortcut and order --- media/forms.py | 1 + media/migrations/0022_auto_20190811_1804.py | 29 ++++++ media/models.py | 7 +- theme/templates/admin/change_form.html | 102 ++++++++++++++++++++ 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 media/migrations/0022_auto_20190811_1804.py create mode 100644 theme/templates/admin/change_form.html diff --git a/media/forms.py b/media/forms.py index cebda4a..94c64c6 100644 --- a/media/forms.py +++ b/media/forms.py @@ -20,6 +20,7 @@ class MediaAdminForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['isbn'].widget.template_name = "media/isbn_button.html" + self.fields['isbn'].widget.attrs.update({'autofocus': 'autofocus'}) def download_data(self, isbn): """ diff --git a/media/migrations/0022_auto_20190811_1804.py b/media/migrations/0022_auto_20190811_1804.py new file mode 100644 index 0000000..4397ca6 --- /dev/null +++ b/media/migrations/0022_auto_20190811_1804.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.4 on 2019-08-11 16:04 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0021_auto_20190811_1047'), + ] + + operations = [ + migrations.AlterModelOptions( + name='auteur', + options={'ordering': ['nom'], 'verbose_name': 'author', 'verbose_name_plural': 'authors'}, + ), + migrations.AlterModelOptions( + name='emprunt', + options={'ordering': ['-date_emprunt'], 'verbose_name': 'borrowed item', 'verbose_name_plural': 'borrowed items'}, + ), + migrations.AlterModelOptions( + name='jeu', + options={'ordering': ['nom'], 'verbose_name': 'game', 'verbose_name_plural': 'games'}, + ), + migrations.AlterModelOptions( + name='media', + options={'ordering': ['title', 'subtitle'], 'verbose_name': 'medium', 'verbose_name_plural': 'media'}, + ), + ] diff --git a/media/models.py b/media/models.py index 5c86ce8..a34de79 100644 --- a/media/models.py +++ b/media/models.py @@ -18,6 +18,7 @@ class Auteur(models.Model): class Meta: verbose_name = _("author") verbose_name_plural = _("authors") + ordering = ['nom'] class Media(models.Model): @@ -62,11 +63,13 @@ class Media(models.Model): ) def __str__(self): - return str(self.title) + ' - ' + str(self.authors.all().first()) + return str(self.title) + ' - ' + str(self.subtitle) \ + + ' - ' + str(self.authors.all().first()) class Meta: verbose_name = _("medium") verbose_name_plural = _("media") + ordering = ['title', 'subtitle'] class Emprunt(models.Model): @@ -97,6 +100,7 @@ class Emprunt(models.Model): class Meta: verbose_name = _("borrowed item") verbose_name_plural = _("borrowed items") + ordering = ['-date_emprunt'] class Jeu(models.Model): @@ -122,3 +126,4 @@ class Jeu(models.Model): class Meta: verbose_name = _("game") verbose_name_plural = _("games") + ordering = ['nom'] diff --git a/theme/templates/admin/change_form.html b/theme/templates/admin/change_form.html new file mode 100644 index 0000000..9ebd41a --- /dev/null +++ b/theme/templates/admin/change_form.html @@ -0,0 +1,102 @@ +{% extends "admin/base_site.html" %} +{% load i18n admin_urls static admin_modify %} + +{% block extrahead %}{{ block.super }} + + {{ media }} +{% endblock %} + +{% block extrastyle %}{{ block.super }} + {% endblock %} + +{% block coltype %}colM{% endblock %} + +{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-form{% endblock %} + +{% if not is_popup %} + {% block breadcrumbs %} + + {% endblock %} +{% endif %} + +{% block content %} +
+ {% block object-tools %} + {% if change %}{% if not is_popup %} + + {% endif %}{% endif %} + {% endblock %} +
{% csrf_token %}{% block form_top %}{% endblock %} +
+ {% if is_popup %}{% endif %} + {% if to_field %}{% endif %} + {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} + {% if errors %} +

+ {% if errors|length == 1 %}{% trans "Please correct the error below." %}{% else %} + {% trans "Please correct the errors below." %}{% endif %} +

+ {{ adminform.form.non_field_errors }} + {% endif %} + + {% block field_sets %} + {% for fieldset in adminform %} + {% include "admin/includes/fieldset.html" %} + {% endfor %} + {% endblock %} + + {% block after_field_sets %}{% endblock %} + + {% block inline_field_sets %} + {% for inline_admin_formset in inline_admin_formsets %} + {% include inline_admin_formset.opts.template %} + {% endfor %} + {% endblock %} + + {% block after_related_objects %}{% endblock %} + + {% block submit_buttons_bottom %}{% submit_row %}{% endblock %} + + {% block admin_change_form_document_ready %} + + {% endblock %} + + {# JavaScript for prepopulated fields #} + {% prepopulated_fields_js %} + +
+
+
+ + {# Bind CTRL+S to Save button #} + +{% endblock %}