mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-20 16:09:54 +00:00
Proposition V1
This commit is contained in:
1 parent
bfa5fa45b8
commit
fc961f6511
36 files changed
+1984
No files matched your search
@@ -0,0 +1,21 @@
|
||||
from core.views.widgets.ajax_select import AutoCompleteSelect
|
||||
|
||||
|
||||
class StockItemSelect(AutoCompleteSelect):
|
||||
def get_context(self, name, value, attrs):
|
||||
self._quantities = {
|
||||
str(item.pk): item.quantity
|
||||
for item in self.choices.queryset.only("pk", "quantity", "item__name")
|
||||
}
|
||||
return super().get_context(name, value, attrs)
|
||||
|
||||
def create_option(
|
||||
self, name, value, label, selected, index, subindex=None, attrs=None
|
||||
):
|
||||
option = super().create_option(
|
||||
name, value, label, selected, index, subindex=subindex, attrs=attrs
|
||||
)
|
||||
quantity = self._quantities.get(str(value))
|
||||
if quantity is not None:
|
||||
option["attrs"]["data-quantity"] = str(quantity)
|
||||
return option
|
||||
Reference in new issue
Block a user