howto disable label for field in admin app form?

723 views
Skip to first unread message

Aljoša Mohorović

unread,
Oct 4, 2011, 8:05:37 AM10/4/11
to django...@googlegroups.com
is it possible to disable rendering of label for field in forms?
i would like to render a field in a custom form (admin add/edit form) w/o label.
any info/tips appreciated

Aljosa

Иван Иванов

unread,
Oct 4, 2011, 8:20:09 AM10/4/11
to django...@googlegroups.com
На Tue, 4 Oct 2011 14:05:37 +0200
Aljoša Mohorović <aljosa.m...@gmail.com> написа:
You can loop through the fields of the form and show only those parts
of the field, you need:

https://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fields

BILLION Sébastien

unread,
Oct 4, 2011, 8:22:40 AM10/4/11
to django...@googlegroups.com, Aljoša Mohorović
It's a strange question...
You can replace an admin template with {% extends "admin/change_form.html %} for example.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/

BILLION Sébastien

the Answer to the ultimate question of life, the universe and everything is 42

http://www.sebastienbillion.com/

Aljoša Mohorović

unread,
Oct 4, 2011, 8:25:41 AM10/4/11
to django...@googlegroups.com
On Tue, Oct 4, 2011 at 2:20 PM, Иван Иванов <wan...@openintegra.com> wrote:
> You can loop through the fields of the form and show only those parts
> of the field, you need:
>
> https://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fields

not exactly what i'm looking for although it works ok for frontend but
my issue is related to admin form.
i can control rendering of form fields but not label, currently the
easiest way seems to be just adding javascript to remove label from
rendered html.

Aljosa

BILLION Sébastien

unread,
Oct 4, 2011, 8:29:07 AM10/4/11
to django...@googlegroups.com, Aljoša Mohorović

Aljoša Mohorović

unread,
Oct 4, 2011, 8:34:56 AM10/4/11
to django...@googlegroups.com
On Tue, Oct 4, 2011 at 2:22 PM, BILLION Sébastien
<sebastie...@gmail.com> wrote:
> It's a strange question...
> You can replace an admin template with {% extends "admin/change_form.html %}
> for example.

i don't see why it's a strange question, i have a form field and i
would like to disable rendering of label?
i appreciate suggestions and did consider overriding admin templates
but "admin/change_form.html" is messy and don't know if it's a smart
thing to do in my case.
i've expected some option where i can set label=None by overriding
field/widget init and disable label.
thanks for suggestions but i think i'll just use javascript to remove label.

Aljosa

Ivan Ivanov

unread,
Oct 4, 2011, 8:46:46 AM10/4/11
to django...@googlegroups.com
Source:
https://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags
If auto_id is False, then the form output will not include <label> tags
nor id attributes:
f = ContactForm(auto_id=False)

I think, this is exactly what you want.

На Tue, 4 Oct 2011 14:34:56 +0200
Aljoša Mohorović <aljosa.m...@gmail.com> написа:

Aljoša Mohorović

unread,
Oct 4, 2011, 9:14:44 AM10/4/11
to django...@googlegroups.com
On Tue, Oct 4, 2011 at 2:46 PM, Ivan Ivanov <wan...@openintegra.com> wrote:
> I think, this is exactly what you want.

i need to do this on field level, not form. thanks for suggestion.
javascript works just fine in this case

Иван Иванов

unread,
Oct 4, 2011, 9:41:35 AM10/4/11
to django...@googlegroups.com
На Tue, 4 Oct 2011 15:14:44 +0200
Aljoša Mohorović <aljosa.m...@gmail.com> написа:
Oh, I see. Yes, this is the only way, beyond extending the admin
template in your case.

Reply all
Reply to author
Forward
0 new messages