kopia lustrzana https://github.com/jedie/PyInventory
Merge pull request #122 from jedie/dev2
NEW: List number of item on `location` change listpull/123/head
commit
3850f9b8a6
|
@ -158,6 +158,7 @@ Files are separated into: "/src/" and "/development/"
|
||||||
* NEW: List all related objects on `item` change page with edit links.
|
* 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.
|
* Change `parent` and `location` fields on `item` change page to a autocompele field.
|
||||||
* Add search to `location`
|
* Add search to `location`
|
||||||
|
* NEW: List number of item on `location` change list
|
||||||
* tbc
|
* tbc
|
||||||
* [v0.16.0 - 14.09.2022](https://github.com/jedie/PyInventory/compare/v0.15.0...0.16.0)
|
* [v0.16.0 - 14.09.2022](https://github.com/jedie/PyInventory/compare/v0.15.0...0.16.0)
|
||||||
* Update requirements
|
* Update requirements
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.db.models import Count
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from import_export.admin import ImportExportMixin
|
from import_export.admin import ImportExportMixin
|
||||||
from import_export.resources import ModelResource
|
from import_export.resources import ModelResource
|
||||||
|
@ -17,13 +18,23 @@ class LocationModelResource(ModelResource):
|
||||||
|
|
||||||
@admin.register(LocationModel)
|
@admin.register(LocationModel)
|
||||||
class LocationModelAdmin(ImportExportMixin, BaseUserAdmin):
|
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'))
|
@admin.display(ordering='path_str', description=_('LocationModel.verbose_name'))
|
||||||
def location(self, obj):
|
def location(self, obj):
|
||||||
text = ' › '.join(obj.path)
|
text = ' › '.join(obj.path)
|
||||||
text = ltruncatechars(text, max_length=settings.TREE_PATH_STR_MAX_LENGTH)
|
text = ltruncatechars(text, max_length=settings.TREE_PATH_STR_MAX_LENGTH)
|
||||||
return text
|
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_display_links = ('location',)
|
||||||
list_filter = (LimitTreeDepthListFilter,)
|
list_filter = (LimitTreeDepthListFilter,)
|
||||||
search_fields = ('name', 'description', 'tags__name')
|
search_fields = ('name', 'description', 'tags__name')
|
||||||
|
|
|
@ -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',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -60,6 +60,7 @@ class ItemModel(BaseParentTreeModel, VersionProtectBaseModel):
|
||||||
location = models.ForeignKey(
|
location = models.ForeignKey(
|
||||||
'inventory.LocationModel',
|
'inventory.LocationModel',
|
||||||
blank=True, null=True, on_delete=models.SET_NULL,
|
blank=True, null=True, on_delete=models.SET_NULL,
|
||||||
|
related_name='items',
|
||||||
verbose_name=_('ItemModel.location.verbose_name'),
|
verbose_name=_('ItemModel.location.verbose_name'),
|
||||||
help_text=_('ItemModel.location.help_text')
|
help_text=_('ItemModel.location.help_text')
|
||||||
)
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue