NEW: List number of item on `location` change list

pull/122/head
JensDiemer 2022-09-30 20:35:01 +02:00
rodzic b0c6acc02a
commit 7d9b6dcabf
4 zmienionych plików z 41 dodań i 1 usunięć

Wyświetl plik

@ -158,6 +158,7 @@ Files are separated into: "/src/" and "/development/"
* NEW: List all related objects on `item` change page with edit links.
* Change `parent` and `location` fields on `item` change page to a autocompele field.
* Add search to `location`
* NEW: List number of item on `location` change list
* tbc
* [v0.16.0 - 14.09.2022](https://github.com/jedie/PyInventory/compare/v0.15.0...0.16.0)
* Update requirements

Wyświetl plik

@ -1,5 +1,6 @@
from django.conf import settings
from django.contrib import admin
from django.db.models import Count
from django.utils.translation import gettext_lazy as _
from import_export.admin import ImportExportMixin
from import_export.resources import ModelResource
@ -17,13 +18,23 @@ class LocationModelResource(ModelResource):
@admin.register(LocationModel)
class LocationModelAdmin(ImportExportMixin, BaseUserAdmin):
@admin.display(ordering='item_count', description=_('ItemModel.verbose_name_plural'))
def item_count(self, obj):
return obj.item_count
@admin.display(ordering='path_str', description=_('LocationModel.verbose_name'))
def location(self, obj):
text = ' '.join(obj.path)
text = ltruncatechars(text, max_length=settings.TREE_PATH_STR_MAX_LENGTH)
return text
list_display = ('location', 'create_dt', 'update_dt')
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.annotate(item_count=Count('items'))
return qs
list_display = ('location', 'create_dt', 'update_dt', 'item_count')
readonly_fields = ('item_count',)
list_display_links = ('location',)
list_filter = (LimitTreeDepthListFilter,)
search_fields = ('name', 'description', 'tags__name')

Wyświetl plik

@ -0,0 +1,27 @@
# Generated by Django 3.2.15 on 2022-09-30 18:30
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0012_parent_tree2'),
]
operations = [
migrations.AlterField(
model_name='itemmodel',
name='location',
field=models.ForeignKey(
blank=True,
help_text='ItemModel.location.help_text',
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='items',
to='inventory.locationmodel',
verbose_name='ItemModel.location.verbose_name',
),
),
]

Wyświetl plik

@ -60,6 +60,7 @@ class ItemModel(BaseParentTreeModel, VersionProtectBaseModel):
location = models.ForeignKey(
'inventory.LocationModel',
blank=True, null=True, on_delete=models.SET_NULL,
related_name='items',
verbose_name=_('ItemModel.location.verbose_name'),
help_text=_('ItemModel.location.help_text')
)