+ Select Location to change +
+-
+
- + + Import + + +
- + + Export + + +
- + + Add Location + + +
+ Filter +
++ By Limit tree depth +
+-
+
- + + All + + +
- + + Only root + + +
- + + Root + first sub + + +
- + + Root + first + second sub + + +
+
diff --git a/src/inventory/admin/location.py b/src/inventory/admin/location.py index a321f6c..6bc2b37 100644 --- a/src/inventory/admin/location.py +++ b/src/inventory/admin/location.py @@ -1,12 +1,14 @@ from django.conf import settings from django.contrib import admin from django.db.models import Count +from django.db.models.options import Options +from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ from import_export.admin import ImportExportMixin from import_export.resources import ModelResource from inventory.admin.base import BaseUserAdmin, LimitTreeDepthListFilter -from inventory.models import LocationModel +from inventory.models import ItemModel, LocationModel from inventory.string_utils import ltruncatechars @@ -22,6 +24,16 @@ class LocationModelAdmin(ImportExportMixin, BaseUserAdmin): def item_count(self, obj): return obj.item_count + @admin.display(description=_('ItemModel.verbose_name_plural')) + def items(self, obj): + item_qs = ItemModel.objects.filter(location=obj) + opts: Options = ItemModel._meta + context = { + 'items': item_qs, + 'opts': opts, + } + return render_to_string('admin/location/items.html', context) + @admin.display(ordering='path_str', description=_('LocationModel.verbose_name')) def location(self, obj): text = ' › '.join(obj.path) @@ -34,7 +46,33 @@ class LocationModelAdmin(ImportExportMixin, BaseUserAdmin): return qs list_display = ('location', 'create_dt', 'update_dt', 'item_count') - readonly_fields = ('item_count',) + fieldsets = ( + ( + _('Internals'), + { + 'classes': ('collapse',), + 'fields': ( + ('id', 'version'), + 'user', + ), + }, + ), + (_('Meta'), {'classes': ('collapse',), 'fields': ('create_dt', 'update_dt')}), + ( + _('Basic'), + { + 'fields': ( + 'name', + 'description', + 'tags', + 'parent', + ) + }, + ), + (_('Items in this Location'), {'fields': ('items',)}), + ) + autocomplete_fields = ('parent',) + readonly_fields = ('id', 'create_dt', 'update_dt', 'user', 'item_count', 'items') list_display_links = ('location',) list_filter = (LimitTreeDepthListFilter,) search_fields = ('name', 'description', 'tags__name') diff --git a/src/inventory/locale/ca/LC_MESSAGES/django.po b/src/inventory/locale/ca/LC_MESSAGES/django.po index 1c4a308..996c704 100644 --- a/src/inventory/locale/ca/LC_MESSAGES/django.po +++ b/src/inventory/locale/ca/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-30 20:11+0200\n" +"POT-Creation-Date: 2022-09-30 20:48+0200\n" "PO-Revision-Date: 2022-09-30 20:07+0200\n" "Last-Translator: Jaume López\n" "Language-Team: \n" @@ -54,9 +54,15 @@ msgstr "Rebuts" msgid "Handed over" msgstr "Donats" +msgid "ItemModel.verbose_name_plural" +msgstr "Elements" + msgid "LocationModel.verbose_name" msgstr "Localització" +msgid "Items in this Location" +msgstr "" + msgid "BaseModel.id.verbose_name" msgstr "ID" @@ -180,9 +186,6 @@ msgstr "Preu de cessió" msgid "ItemModel.handed_over_price.help_text" msgstr " " -msgid "ItemModel.verbose_name_plural" -msgstr "Elements" - msgid "ItemLinkModel.verbose_name" msgstr "Vincle" diff --git a/src/inventory/locale/de/LC_MESSAGES/django.mo b/src/inventory/locale/de/LC_MESSAGES/django.mo index 45da557..7d52236 100644 Binary files a/src/inventory/locale/de/LC_MESSAGES/django.mo and b/src/inventory/locale/de/LC_MESSAGES/django.mo differ diff --git a/src/inventory/locale/de/LC_MESSAGES/django.po b/src/inventory/locale/de/LC_MESSAGES/django.po index e00a82d..13262b6 100644 --- a/src/inventory/locale/de/LC_MESSAGES/django.po +++ b/src/inventory/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-30 20:11+0200\n" -"PO-Revision-Date: 2022-09-30 20:10+0200\n" +"POT-Creation-Date: 2022-09-30 20:48+0200\n" +"PO-Revision-Date: 2022-09-30 20:48+0200\n" "Last-Translator: Jens Diemer\n" "Language-Team: \n" "Language: de\n" @@ -54,9 +54,15 @@ msgstr "Erhalt" msgid "Handed over" msgstr "Abgabe" +msgid "ItemModel.verbose_name_plural" +msgstr "Gegenstände" + msgid "LocationModel.verbose_name" msgstr "Standort" +msgid "Items in this Location" +msgstr "Gegenstände an diesem Ort:" + msgid "BaseModel.id.verbose_name" msgstr "ID" @@ -179,9 +185,6 @@ msgstr "Abgabepreis" msgid "ItemModel.handed_over_price.help_text" msgstr "Wurde bei der Abgabe Geld eingenommen?" -msgid "ItemModel.verbose_name_plural" -msgstr "Gegenstände" - msgid "ItemLinkModel.verbose_name" msgstr "Link" diff --git a/src/inventory/locale/en/LC_MESSAGES/django.po b/src/inventory/locale/en/LC_MESSAGES/django.po index 5e3e1dd..2ca0df1 100644 --- a/src/inventory/locale/en/LC_MESSAGES/django.po +++ b/src/inventory/locale/en/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-30 20:11+0200\n" +"POT-Creation-Date: 2022-09-30 20:48+0200\n" "PO-Revision-Date: 2021-10-09 19:36+0200\n" "Last-Translator: Jens Diemer\n" "Language-Team: \n" @@ -54,9 +54,15 @@ msgstr "" msgid "Handed over" msgstr "" +msgid "ItemModel.verbose_name_plural" +msgstr "Items" + msgid "LocationModel.verbose_name" msgstr "Location" +msgid "Items in this Location" +msgstr "" + msgid "BaseModel.id.verbose_name" msgstr "ID" @@ -179,9 +185,6 @@ msgstr "Handed over price" msgid "ItemModel.handed_over_price.help_text" msgstr " " -msgid "ItemModel.verbose_name_plural" -msgstr "Items" - msgid "ItemLinkModel.verbose_name" msgstr "Link" diff --git a/src/inventory/locale/es/LC_MESSAGES/django.po b/src/inventory/locale/es/LC_MESSAGES/django.po index baf1369..369e289 100644 --- a/src/inventory/locale/es/LC_MESSAGES/django.po +++ b/src/inventory/locale/es/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-30 20:11+0200\n" +"POT-Creation-Date: 2022-09-30 20:48+0200\n" "PO-Revision-Date: 2021-10-09 19:36+0200\n" "Last-Translator: Jaume López\n" "Language-Team: \n" @@ -54,9 +54,15 @@ msgstr "Recibidos" msgid "Handed over" msgstr "Cedidos" +msgid "ItemModel.verbose_name_plural" +msgstr "Elementos" + msgid "LocationModel.verbose_name" msgstr "Localización" +msgid "Items in this Location" +msgstr "" + msgid "BaseModel.id.verbose_name" msgstr "ID" @@ -180,9 +186,6 @@ msgstr "Precio de cesión" msgid "ItemModel.handed_over_price.help_text" msgstr " " -msgid "ItemModel.verbose_name_plural" -msgstr "Elementos" - msgid "ItemLinkModel.verbose_name" msgstr "Vínculo" diff --git a/src/inventory/templates/admin/location/items.html b/src/inventory/templates/admin/location/items.html new file mode 100644 index 0000000..6e63863 --- /dev/null +++ b/src/inventory/templates/admin/location/items.html @@ -0,0 +1,18 @@ +{% load i18n admin_urls %} + +
{% trans "No." %} | +{% trans "ItemModel.verbose_name_plural" %} | +
---|---|
{{ forloop.counter }} | +{{ obj }} | +
0 Locations
', + ), + ) + assert_html_response_snapshot(response=response, validate=False) diff --git a/src/inventory/tests/test_admin_location_empty_change_list_1.snapshot.html b/src/inventory/tests/test_admin_location_empty_change_list_1.snapshot.html new file mode 100644 index 0000000..a16e0bc --- /dev/null +++ b/src/inventory/tests/test_admin_location_empty_change_list_1.snapshot.html @@ -0,0 +1,77 @@ +