2024-07-09 15:31:24 +00:00
|
|
|
from django import forms
|
|
|
|
from lot.models import Lot
|
|
|
|
|
|
|
|
class LotsForm(forms.Form):
|
|
|
|
lots = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Lot.objects.all(),
|
|
|
|
widget=forms.CheckboxSelectMultiple,
|
|
|
|
)
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
# import pdb; pdb.set_trace()
|
|
|
|
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
|