remove devices from a lot
This commit is contained in:
parent
65ad4a04e4
commit
9f37c8fbd7
|
@ -50,7 +50,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -15,8 +15,13 @@ class LotsForm(forms.Form):
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
if not commit:
|
if not commit:
|
||||||
return
|
return
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
for dev in self.devices:
|
for dev in self.devices:
|
||||||
for lot in self._lots:
|
for lot in self._lots:
|
||||||
lot.devices.add(dev.id)
|
lot.devices.add(dev.id)
|
||||||
return
|
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("add/", views.NewLotView.as_view(), name="add"),
|
||||||
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
|
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
|
||||||
path("add/devices/", views.AddToLotView.as_view(), name="add_devices"),
|
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
|
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