Adding sign on required fields in django form

25 views
Skip to first unread message

Harjot Mann

unread,
Dec 5, 2013, 3:29:20 AM12/5/13
to django...@googlegroups.com
In django form I want to add a * symbol on those fields which are
compulsory so that user can recognize from the name of the field that
this field is required field.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

Mike Dewhirst

unread,
Dec 5, 2013, 3:51:44 AM12/5/13
to django...@googlegroups.com
On 5/12/2013 7:29pm, Harjot Mann wrote:
> In django form I want to add a * symbol on those fields which are
> compulsory so that user can recognize from the name of the field that
> this field is required field.
>

I've never done this in Django but normally I would use a CSS class. Try
looking up model field properties and if blank == False then make the
field widget nominate the "compulsory" CSS class.

I know this is nothing to do with your question but I use the following
utility function to return a verbose name. Maybe you can explore for the
value of a field's "blank" property instead of "verbose_name" ...

def verbose_name(obj, field):
return
obj.__class__()._meta.get_field_by_name('{0}'.format(field))[0].verbose_name

Good luck

Mike

Larry Martell

unread,
Dec 5, 2013, 6:20:02 AM12/5/13
to django...@googlegroups.com
On Thu, Dec 5, 2013 at 3:29 AM, Harjot Mann <harjotm...@gmail.com> wrote:
> In django form I want to add a * symbol on those fields which are
> compulsory so that user can recognize from the name of the field that
> this field is required field.

You could use the HTML placeholder attribute.
Reply all
Reply to author
Forward
0 new messages