Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Obtaining field name in template
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Axel Rau  
View profile  
 More options Nov 12 2012, 4:52 pm
From: Axel Rau <Axel....@Chaos1.DE>
Date: Mon, 12 Nov 2012 22:51:45 +0100
Local: Mon, Nov 12 2012 4:51 pm
Subject: Obtaining field name in template
1st trial with generic views:

url.py:
    url(r'^account/(?P<pk>\d+)/$', AccountDetailView.as_view(), name='account-detail'),

views.py:
class AccountDetailView(DetailView):
        model = Account

In the template, I get the data so:
        object.field
But how do I get the field name (model.field.verbose_name)?

Axel
---
PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lachlan Musicman  
View profile  
 More options Nov 12 2012, 5:00 pm
From: Lachlan Musicman <data...@gmail.com>
Date: Tue, 13 Nov 2012 09:59:43 +1200
Local: Mon, Nov 12 2012 4:59 pm
Subject: Re: Obtaining field name in template

On Tue, Nov 13, 2012 at 9:51 AM, Axel Rau <Axel....@chaos1.de> wrote:
> 1st trial with generic views:

> url.py:
>     url(r'^account/(?P<pk>\d+)/$', AccountDetailView.as_view(), name='account-detail'),

> views.py:
> class AccountDetailView(DetailView):
>         model = Account

> In the template, I get the data so:
>         object.field
> But how do I get the field name (model.field.verbose_name)?

I think the easiest way I've seen is to use _meta like thus:

http://stackoverflow.com/questions/3647805/get-models-fields-in-django

cheers
L.

--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Axel Rau  
View profile  
 More options Nov 13 2012, 8:23 am
From: Axel Rau <Axel....@Chaos1.DE>
Date: Tue, 13 Nov 2012 14:23:00 +0100
Subject: Re: Obtaining field name in template
Am 12.11.2012 um 22:59 schrieb Lachlan Musicman:

Thanks for the pointers, but none of them shows how to access the field meta out of a template from a single query result object.
I can't call functions with arguments (fieldname) out of a template and I'm not in a loop context there.

Axel
---
PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lachlan Musicman  
View profile  
 More options Nov 13 2012, 2:02 pm
From: Lachlan Musicman <data...@gmail.com>
Date: Wed, 14 Nov 2012 07:01:37 +1200
Local: Tues, Nov 13 2012 2:01 pm
Subject: Re: Obtaining field name in template

AH! If I remember correctly, I also asked about this when I started
using Django. There's a reason you can't call complex functions in the
template: code separation/DRY/etc.

If you want the data, get it in views.py and pass it to the template.
The heavy lifting should be done in the views.py (as functions) or
models.py (as class methods) and then passed into the template using
the context.

I was frustrated by this at first, but by the end I was a convert -
makes things much cleaner.

cheers
L.

--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »