remove devices from a lot
This commit is contained in:
parent
65ad4a04e4
commit
9f37c8fbd7
|
@ -50,7 +50,7 @@
|
|||
</tbody>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<button type="submit" value="/lot/devices/remove" name="url">Remove</button> <button type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
|
||||
<button type="submit" value="{% url 'lot:del_devices' %}" name="url">Remove</button> <button type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -15,8 +15,13 @@ class LotsForm(forms.Form):
|
|||
def save(self, commit=True):
|
||||
if not commit:
|
||||
return
|
||||
# import pdb; pdb.set_trace()
|
||||
for dev in self.devices:
|
||||
for lot in self._lots:
|
||||
lot.devices.add(dev.id)
|
||||
return
|
||||
|
||||
def remove(self):
|
||||
for dev in self.devices:
|
||||
for lot in self._lots:
|
||||
lot.devices.remove(dev.id)
|
||||
return
|
||||
|
|
|
@ -7,4 +7,5 @@ urlpatterns = [
|
|||
path("add/", views.NewLotView.as_view(), name="add"),
|
||||
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
|
||||
path("add/devices/", views.AddToLotView.as_view(), name="add_devices"),
|
||||
path("del/devices/", views.DelToLotView.as_view(), name="del_devices"),
|
||||
]
|
||||
|
|
11
lot/views.py
11
lot/views.py
|
@ -87,3 +87,14 @@ class AddToLotView(DashboardView, FormView):
|
|||
return response
|
||||
|
||||
|
||||
class DelToLotView(AddToLotView):
|
||||
title = _("Remove from lots")
|
||||
breadcrumb = "lot / remove from lots"
|
||||
|
||||
def form_valid(self, form):
|
||||
form.devices = self.get_session_devices()
|
||||
form.remove()
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue