Your form need a attribute named enctype, and the value is
multipart/form-data, try it.
在 2012-5-19 晚上10:55,"Michael Ackerman" <binary...@gmail.com>写道:
>
> I have a generic view:
>
> class create_ticket(CreateView):
>     model = ticket
>     form_class = ticket_form
>     template_name = "create_ticket.html"
>     success_url = "/tickets/thanks/"
>
> and a form:
>
> class ticket_form(ModelForm):
>     class Meta:
>         model = ticket
>         fields = ('title','description','picture')
>
> But when I try to submit the data, it get a "This field is required" for
the picture, so I think I'm missing something in order to take in the
picture.
>
> and for reference:
>
> #create_ticket.html:
> {% extends "base.html" %}
> {% block main %}
> <form action="" method="post">{% csrf_token %}
>     {{ form.as_table}}
> <input type="submit" value="Submit" />
> </form>
> {% endblock %}
>
> #models.py
> class ticket(models.Model):
>     title = models.CharField(max_length = 100)
>     date_created = models.DateTimeField(auto_now_add=True)
>     description = models.TextField()
>     ranking = models.PositiveIntegerField(default=0)
>     picture = models.ImageField(
>         upload_to ='pictures' )
>
>     def __unicode__(self):
>         return self.title
>
> All help is appreciated, thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to