2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-22 02:59:34 +00:00

Selection lists updates (#11705)

* Add search capability to selection list entry endpoint

* Use API lookup for selection entries

* Add renderer func

* Allow API filtering

* Fetch selectionentry data related to the selected data item

* remove now unneeded entry

* add missing modelinfo

* fix ref

* add api bump

* Provide optional single fetch function to API forms

- Useful if we need to perform a custom API call for initial data

* django-admin support for SelectionList

* Docstring improvements

* Apply 'active' filter

* Tweak api version entry

* Playwright tests

* Tweak docs wording

* Fix incorrect docstring

* Adjust playwright tests

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
Oliver
2026-04-10 09:22:12 +10:00
committed by GitHub
parent 6701f4085d
commit 9965ebcfa1
22 changed files with 325 additions and 84 deletions

View File

@@ -1,11 +1,14 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 475
INVENTREE_API_VERSION = 476
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v476 -> 2026-04-09 : https://github.com/inventree/InvenTree/pull/11705
- Adds sorting / filtering / searching functionality to the SelectionListEntry API endpoint
v475 -> 2026-04-09 : https://github.com/inventree/InvenTree/pull/11702
- Adds "updated" and "updated_by" fields to the LabelTemplate and ReportTemplate API endpoints

View File

@@ -32,6 +32,24 @@ class ParameterAdmin(admin.ModelAdmin):
search_fields = ('template__name', 'data', 'note')
class SelectionListEntryInlineAdmin(admin.StackedInline):
"""Inline admin class for the SelectionListEntry model."""
model = common.models.SelectionListEntry
extra = 0
@admin.register(common.models.SelectionList)
class SelectionListAdmin(admin.ModelAdmin):
"""Admin interface for SelectionList objects."""
list_display = ('name', 'description')
search_fields = ('name', 'description')
list_filter = ('active', 'locked')
inlines = [SelectionListEntryInlineAdmin]
@admin.register(common.models.Attachment)
class AttachmentAdmin(admin.ModelAdmin):
"""Admin interface for Attachment objects."""

View File

@@ -1166,6 +1166,14 @@ class EntryMixin:
class SelectionEntryList(EntryMixin, ListCreateAPI):
"""List view for SelectionEntry objects."""
filter_backends = SEARCH_ORDER_FILTER
ordering_fields = ['list', 'label', 'active']
search_fields = ['label', 'description']
filterset_fields = ['active', 'value', 'list']
class SelectionEntryDetail(EntryMixin, RetrieveUpdateDestroyAPI):
"""Detail view for a SelectionEntry object."""

View File

@@ -2320,11 +2320,39 @@ class SelectionList(InvenTree.models.MetadataMixin, InvenTree.models.InvenTreeMo
"""Return the API URL associated with the SelectionList model."""
return reverse('api-selectionlist-list')
def get_choices(self):
"""Return the choices for the selection list."""
choices = self.entries.filter(active=True)
def get_choices(self, active: Optional[bool] = True):
"""Return the choices for the selection list.
Arguments:
active: If specified, filter choices by active status
Returns:
List of choice values for this selection list
"""
choices = self.entries.all()
if active is not None:
choices = choices.filter(active=active)
return [c.value for c in choices]
def has_choice(self, value: str, active: Optional[bool] = None):
"""Check if the selection list has a particular choice.
Arguments:
value: The value to check for
active: If specified, filter choices by active status
Returns:
True if the choice exists in the selection list, False otherwise
"""
choices = self.entries.all()
if active is not None:
choices = choices.filter(active=active)
return choices.filter(value=value).exists()
class SelectionListEntry(models.Model):
"""Class which represents a single entry in a SelectionList.