You need to set Form.required_css_class

https://docs.djangoproject.com/en/1.8/ref/forms/api/#styling-required-or-erroneous-form-rows

On Fri, Apr 24, 2015 at 2:30 PM, victor menezes
<menezes.vic...@gmail.com> wrote:
> Hi all,
>
> I'm using Django 1.8 and having trouble to because my form does not generate
> fields with required option even though they have the property "blank=False"
> in the model.
> In the example bellow, shouldn't the field "description" have the "required"
> attribute in the html generated using "form.as_p" or am I missing anything?
>
> models.py
> class Place(models.Model):
>     name = models.CharField(max_length=200, blank=False, default='')
>     owners = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=False)
>     members = models.ManyToManyField(Member, blank=True)
>     description =  models.TextField(blank=False)
>     location = models.CharField(max_length=400, blank=True)
>     additional_info = models.TextField(blank=True)
>
>     def __unicode__(self):
>         return self.name
>
>
> class PlaceForm(ModelForm):
>     class Meta:
>         model = Place
>         fields = '__all__'
>
> views.py
> @login_required(login_url='/')
> def addPlaceView(request):
>     place_form = PlaceForm()
>     context = {
>         'form': place_form,
>     }
>     return render(request, 'newPlace.html', context)
>
> newPlace.html
> <form action="/newplace/" method="post">
>     {% csrf_token %}
>     {{ form.as_p }}
>     <input type="submit" value="Submit" />
> </form>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/84a2cdf8-f6de-438b-b7d3-775c4300f105%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxU9Ng-2pjkakwM7AZDBgt5McQiv%3D%2Bn75L3SotMsMi5boA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to