devicehub-django/lot/forms.py

29 lines
648 B
Python
Raw Permalink Normal View History

2024-07-09 15:31:24 +00:00
from django import forms
from lot.models import Lot
2024-07-30 20:54:00 +00:00
2024-07-09 15:31:24 +00:00
class LotsForm(forms.Form):
lots = forms.ModelMultipleChoiceField(
queryset=Lot.objects.all(),
widget=forms.CheckboxSelectMultiple,
)
def clean(self):
self._lots = self.cleaned_data.get("lots")
return self._lots
def save(self, commit=True):
if not commit:
return
2024-07-19 15:40:01 +00:00
2024-07-09 15:31:24 +00:00
for dev in self.devices:
for lot in self._lots:
2024-07-19 15:40:01 +00:00
lot.add(dev.id)
2024-07-09 15:31:24 +00:00
return
2024-07-10 08:24:40 +00:00
def remove(self):
for dev in self.devices:
for lot in self._lots:
2024-07-19 15:40:01 +00:00
lot.remove(dev.id)
2024-07-10 08:24:40 +00:00
return