mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-21 23:42:14 +00:00
Started work on improving asset form update and validation - requires de-spaghettifying of asset_update.html before continuing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from assets import models
|
||||
|
||||
@@ -7,7 +8,15 @@ class AssetForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = models.Asset
|
||||
fields = '__all__'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AssetForm, self).__init__(*args, **kwargs)
|
||||
self.fields['asset_id'].disabled = True #You should not be able to change the asset ID, either in update or create
|
||||
|
||||
def clean_date_sold(self):
|
||||
if self.cleaned_data["date_sold"] and self.cleaned_data["date_acquired"] > self.cleaned_data["date_sold"]:
|
||||
raise ValidationError("Cannot sell an item before it is acquired")
|
||||
return self.cleaned_data["date_sold"]
|
||||
|
||||
class SupplierForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user