From 7359e05427e9c0ca9cb0a6e7cb5d30e96acd469e Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Sat, 5 Oct 2019 21:16:03 +0100 Subject: [PATCH] Started adding functionality for assets and cables forms to be dynamically swapped --- assets/forms.py | 5 +++++ assets/views.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/assets/forms.py b/assets/forms.py index d1a24ef0..3b5ec6ea 100644 --- a/assets/forms.py +++ b/assets/forms.py @@ -14,6 +14,11 @@ class AssetForm(forms.ModelForm): raise ValidationError("Cannot sell an item before it is acquired") return self.cleaned_data["date_sold"] +class CableForm(AssetForm): + class Meta: + model = models.Cable + fields = '__all__' + class SupplierForm(forms.ModelForm): class Meta: model = models.Supplier diff --git a/assets/views.py b/assets/views.py index 02e51892..9549a5c4 100644 --- a/assets/views.py +++ b/assets/views.py @@ -13,6 +13,12 @@ from dateutil import parser import simplejson as json from assets import models, forms +class CableFormMixin: + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["cableForm"] = forms.CableForm + return context + class AssetList(LoginRequiredMixin, generic.ListView): model = models.Asset template_name = 'asset_list.html'