bryansis2010 bryansis2010 - 9 months ago 17
Python Question

Ticket amount resolves to Null in Django Form

I have a simple TicketForm which is a Django Form. I want to override the cleanfield methods in Django 1.8

class TicketForm(forms.Form):
ticket_amount = forms.DecimalField(label="Ticket Amount", required=True)
name = forms.CharField(label="Name",required=False)

def clean_ticket_amount(self):
ticket_amount = self.cleaned_data.get('ticket_amount', None)
if ticket_amount <= 0.00:
raise forms.ValidationError("Ticket values cannot be below $0.00")

def save(self):
#some other code

When I do something like
I get an output as so:

{'name': "some_name", 'ticket_amount': {...}}

And then I cannot process it. Otherwise I've seen the
'ticket_amount'= NoneType
error. Did I implement the clean methods wrongly?


The answer is to put return ticket_amount at the end of the method.