Ok. So it seems you can't access the field verbose_name without a little
trickery. So here is how I did it.

Model:
def get_fields(self):
        return [(field.name, field.value_to_string(self)) for field in
self._meta.fields]

Template Filter:
@register.filter
def get_verbose_name(model, field):
    return send = model._meta.get_field('%s' % field).verbose_name
get_verbose_name.is_safe = True

Template:
{% for name, value in inspection.get_fields %}
<tr class="{% cycle 'odd' 'even' %}">
<th>{{ inspection|get_verbose_name:name }}</th>
<td>
{{ value }}
</td>
</tr>
{% endfor %}

If anyone sees any major problems with this please let me know. But it seems
to work quite well.

Greg

On Thu, Feb 24, 2011 at 9:15 AM, Greg Corey <gregco...@gmail.com> wrote:

> Pardon the continued confusion, but the problem is that I don't know how to
> access the model field to get it's associated label like I can when
> rendering a form. I don't want to manually type out each label text in my
> template because I like knowing that if I do need to change the label, I can
> change it in the model and then I don't have to worry about my templates
> because they just reference the model (DRY).
>
> Thanks for you help.
>
> Greg
>
>
> On Wed, Feb 23, 2011 at 5:22 PM, Mike Ramirez <gufym...@gmail.com> wrote:
>
>>  On Wednesday, February 23, 2011 04:16:51 pm Greg Corey wrote:
>>
>> > Thanks for your reply. One question.
>>
>> >
>>
>> > > make sure to reference the model field you want as the label if
>>
>> > > 'Requester' isn't it.
>>
>> >
>>
>> > Not sure what you mean by this. Do you just mean manually change
>>
>> > 'Requester' to whatever I want, or that I really can reference the model
>>
>> > field to get the label?
>>
>> >
>>
>> > Greg
>>
>> >
>>
>> Both, what ever fits your needs.
>>
>> Mike
>>
>> --
>>
>> To be trusted is a greater compliment than to be loved.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to