Django form doesn't validate, have no idea why. Originally I supposed it was because I added one more hidden input filed to the form(is is actually allowed? found nothing related in docs ) but I deleted it and nothing changed.
the form:
class TicketForm(forms.ModelForm):
class Meta:
model = Ticket
fields = ('upload','ownership','price','comment','ticket_type')
widgets = {
'upload': forms.FileInput(
attrs={'id': 'fileinput', 'required': True, 'name':'pdf', 'placeholder': 'Say something...'}
),
}
model:
class Ticket(models.Model):
upload = models.FileField(upload_to='media/tickets/')
ownership = models.ForeignKey(UserProfile)
event = models.ForeignKey(Event)
comment = models.CharField(max_length=2000)
approved = models.BooleanField(default=False)
sold = models.BooleanField(default=False)
price = models.IntegerField(blank=False, default=0)
TICKET_CHOICES = (
('DG', 'Digital'),
('RL', 'Real'),
)
ticket_type = models.CharField(
max_length=2,
choices=TICKET_CHOICES,
default='Digital',
)
in template:
<form method='POST' action="/upload_ticket/" class="pdf_form">
{% csrf_token %}
{{ form.as_p }}
<!-- <input type="hidden" id="pk_input" value="{{ selected.id}}" name="event_id"></input> -->
<input type="submit" id='submit_hidden'>Save</input>
</form>
In views if I remove if form.is_valid()
the error is obvious The Ticket could not be created because the data didn't validate.
The file to be loaded is pdf file.
Do you have any ideas why it doesn't validate?