How does admin generate HTML for adding objects?

0 views
Skip to first unread message

Technicalbard

unread,
Jul 2, 2009, 6:02:44 PM7/2/09
to Django users
I'm curious how the admin creates the templates for any object in the
database...

I'm using the object_detail generic view, but would prefer having
Django use the parameters of the object to generate the template,
rather than me having to hardcode the parameter names into the
template.

The admin does this when you create new objects - how? The docs don't
seem to lead me to this.

TechnicalBard

unread,
Jul 3, 2009, 1:06:02 AM7/3/09
to Django users
To clarify, the djangobook states:

<< On the admin site’s edit forms, each field’s label is generated
from its model field name. The algorithm is simple: Django just
replaces underscores with spaces and capitalizes the first character,
so, for example, the Book model’s publication_date field has the label
“Publication date.” >>

Where in the django.contrib.admin code is this logic found? I would
like to utilize it.

Jonathan Buchanan

unread,
Jul 3, 2009, 3:16:08 AM7/3/09
to django...@googlegroups.com
On Fri, Jul 3, 2009 at 6:06 AM, TechnicalBard<rodw...@gmail.com> wrote:
>
> To clarify, the djangobook states:
>
> << On the admin site’s edit forms, each field’s label is generated
> from its model field name. The algorithm is simple: Django just
> replaces underscores with spaces and capitalizes the first character,
> so, for example, the Book model’s publication_date field has the label
> “Publication date.” >>
>
> Where in the django.contrib.admin code is this logic found?  I would
> like to utilize it.

This is part of the forms library - django.forms.forms.pretty_name [1]
is used [2] to generate a label from the field name if a label was not
given when the field was instantiated.

Jonathan.

[1] http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py#L20
[2] http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py#L346

Chhouk Voeun

unread,
Jul 3, 2009, 3:21:40 AM7/3/09
to django...@googlegroups.com
I want to stop join group

TechnicalBard

unread,
Jul 3, 2009, 12:21:49 PM7/3/09
to Django users
Thanks!

Related question: when displaying a ModelForm, how does Django
iterate/enumerate how many fields the model has?


On Jul 3, 1:16 am, Jonathan Buchanan <jonathan.bucha...@gmail.com>
wrote:
> On Fri, Jul 3, 2009 at 6:06 AM, TechnicalBard<rodwe...@gmail.com> wrote:
>
> > To clarify, the djangobook states:
>
> > << On the admin site’s edit forms, each field’s label is generated
> > from its model field name. The algorithm is simple: Django just
> > replaces underscores with spaces and capitalizes the first character,
> > so, for example, the Book model’s publication_date field has the label
> > “Publication date.” >>
>
> > Where in the django.contrib.admin code is this logic found?  I would
> > like to utilize it.
>
> This is part of the forms library - django.forms.forms.pretty_name [1]
> is used [2] to generate a label from the field name if a label was not
> given when the field was instantiated.
>
> Jonathan.
>
> [1]http://code.djangoproject.com/browser/django/trunk/django/forms/forms...
> [2]http://code.djangoproject.com/browser/django/trunk/django/forms/forms...
Reply all
Reply to author
Forward
0 new messages