On Dec 22, 4:43 pm, nbv4 <cp368...@ohio.edu> wrote:
> I have a model which is defines kind of like this:
>
> MyModel(models.Model)
>     field1 = models.BooleanField()
>     field2 = models.BooleanField()
>     field_num = "1"
>
> And then I have a form thats pretty much this:
>
> MyModelForm(models.ModelForm)
>     class meta
>         model = MyModel
>
> I want to be able to access the "field_num" value from the form
> object. So I can do this in a template:
>
> <tr class="field-{{ form.field_num }}">
>     <td>{{form.field1 }}</td>
>     <td>{{form.field2 }}</td>
> </tr>
>
> How can I do this? I'm sorta new to Python/Django
The attribute won't be added to the form, because it isn't a field.
However, a modelform always has an 'instance' attribute, which is a
reference to the model instance used to populate the form, or a blank
one. So you should be able to do:
{{ form.instance.field_num }}

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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