Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 15, 2005 23:16:08

oggie r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


Hi,
There is one part of the design that puzzles me. Considering DRY and
simple design goals, it is odd that you have to define a very specific
template to cover even a generic view.
For example, I have a Client(Person) model (Person is a subclass as it
holds general info like names, addresses, etc), a generic create/update
view and I have written very little code. But when I get to the
template, no scalable option is obvious. I would expect something like:
(% for field in form.fields %)
<tr>
<td><label>{{field.name_formatted}}</label></td>
<td>{{field}}</td>
</td>
(% endfor %)
but instead I am looking at:
<tr>
<td><label>First Name</label></td>
<td>{{form.first_name}}</td>
</tr>
<tr>
<td><label>Last Name</label></td>
<td>{{form.last_name}}</td>
</tr>
<tr>
<td>... etc

Although I see some sense to separating formatting from model, there is
a chance that you can miss a field here or there. Plus most of my
tables are very boring, fairly large tables and I certainly don't want
to spend much time on the templates for them. I also don't want to use
the admin interface because it is too specific - so what should I do?

I completely understand if this is already documented - apologies if so.

Offline

#2 Nov. 15, 2005 23:29:45

Jacob K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


On Nov 15, 2005, at 5:09 PM, oggie rob wrote:But when I get to thetemplate, no scalable option is obvious. I would expect somethinglike:(% for field in form.fields %)

As of revision this is now possible.

Enjoy!

Jacob

Offline

#3 Nov. 15, 2005 23:55:36

oggie r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


Holy moly! That's exactly it! Thanks for the change - I had been
looking for a while and my head was starting to swim!

Offline

#4 Nov. 17, 2005 10:35:20

Pedro F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


2005/11/15, oggie rob <>:
>
> Holy moly! That's exactly it! Thanks for the change - I had been
> looking for a while and my head was starting to swim!
>

How can I get the verbose_name of the field?

{{ field.verbose_name }} doesn't work. Checked the source and it seams
FormField class and its widgets only provides the field_name.

Thanks,
Pedro

Offline

#5 Nov. 17, 2005 14:25:20

Adrian H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


On 11/17/05, Pedro Furtado <> wrote:
> How can I get the verbose_name of the field?
>
> {{ field.verbose_name }} doesn't work. Checked the source and it seams
> FormField class and its widgets only provides the field_name.

You're correct: FormField classes have no knowledge of model objects.
All they know about is the basics for displaying a form. If you want
to pass the verbose_name of a model object, you'll need to create some
sort of custom data structure and pass it to your template.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Offline

#6 Nov. 17, 2005 15:06:41

Pedro F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


> You're correct: FormField classes have no knowledge of model objects.
> All they know about is the basics for displaying a form. If you want
> to pass the verbose_name of a model object, you'll need to create some
> sort of custom data structure and pass it to your template.

Thanks

--
Pedro Furtado

Offline

#7 Nov. 23, 2005 06:39:13

Bryan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

DRY templates


On 11/15/05, Jacob Kaplan-Moss <> wrote:
>
> On Nov 15, 2005, at 5:09 PM, oggie rob wrote:
> > But when I get to the
> > template, no scalable option is obvious. I would expect something
> > like:
> > (% for field in form.fields %)
>
>
> As of revision this is now possible.

I'm trying this out for an update_object generic view. Very nice.
One little issue though, for most of the fields it puts in the
original value from the object that is to be updated, except the
foreign key selects it doesn't pre-select the value that is already
set for that object. How can I have it do that for me too?

Bryan

Offline

Board footer

Moderator control

Enjoy the 24th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support