You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, these are the problems with validation of pool form:
Seats can be assigned zero and negative values.
User can select any past datetime values.
Source and Destination can be same.
Unpaid trips store the amount in database(if the paid box is unchecked, then the amount stored in database should be 0)
Amount on paid trips cannot be negative
Solution
We can override the default form.clean() method on class PoolForm() and make a custom clean method.
def clean(self):
cleaned_data = super(PoolForm,self).clean()
if cleaned_data.get('tot') <= 0:
raise forms.ValidationError("There should be atleast 1 seats")
if datetime.strptime(cleaned_data.get('dateTime'),"%Y-%m-%d %H:%M") <= datetime.now():
raise forms.ValidationError("Selected DateTime has passed. Please select a valid date.")
if cleaned_data.get('source') == cleaned_data.get('dest'):
raise forms.ValidationError("Source and Destination should be different")
if cleaned_data.get('paid') == False:
self.cleaned_data['amount']=0
else :
if cleaned_data.get('amount') < 0:
raise forms.ValidationError("Amount should be positive")
return cleaned_data
Problem
Currently, these are the problems with validation of pool form:
Solution
We can override the default
form.clean()
method onclass PoolForm()
and make a custom clean method.@dipanshu231099 Please review this issue and its solution
The text was updated successfully, but these errors were encountered: