On 24/01/2013 10:46am, frocco wrote:
> Thanks Mike,
>
> I do not know if this will work.
> I want to change the field in the template as I read each row.
> I do this in PHP rather easy, but am confused on how to do this using
> django.
I haven't done much php (only emergency repairs to stuff written by
others after they have disappeared!) so I don't know how easy that might be.
In Django templates you can use HTML and for-loops to do most things.
You just write a class in your view to get the data from a query_set and
construct a list of objects (in your case, each row and a list of all of
its individual choices as found - foreign key or many-to-many - in the
database) and render it in your template. There is plenty of template
power available ...
https://docs.djangoproject.com/en/1.4/ref/templates/builtins/
It might look like this ...
{% if list_of_row_objects %}
<ul>
{% for row_object in list_of_row_objects %}
<li>{{ row_object.field_name }}
<p>There are {{ row_object.choices|length }} choices
<ol>
{% for choice in row_object.choices %}
<li>{{
choice.name }}</li>
{% empty %}
<li>There are no choices for this row</li>
{% endfor %}
</ol>
</li>
{% endfor %}
</ul>
{% else %}
<p>Sorry, no list of row objects today!</p>
{% endif %}
hth
Mike
>
>
> On Wednesday, January 23, 2013 6:03:28 PM UTC-5, Mike Dewhirst wrote:
>
> On 24/01/2013 2:36am, frocco wrote:
> > Hello,
> >
> > In my view, I am displaying rows of data that have a choice field
> in a form.
> > one form for each row
> >
> > I want to change the choice this before printing.
> >
> > one row can have 1 to 5 choices
> > another row can have 1 to 10 choices depending on values in each
> row.
>
> I'm likely to want something similar soon so I googled "how do I
> dynamically modify a django choice field" and got at least a page of
> results. Here is one which I looked at and found interesting. It may
> suit your needs ...
>
>
http://ilian.i-n-i.org/django-forms-choicefield-with-dynamic-values/
> <
http://ilian.i-n-i.org/django-forms-choicefield-with-dynamic-values/>
>
> Good luck
>
> Mike
>
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To view this discussion on the web visit
> >
https://groups.google.com/d/msg/django-users/-/BSrfbUYb_v8J
> <
https://groups.google.com/d/msg/django-users/-/BSrfbUYb_v8J>.
> <javascript:>.
> > To unsubscribe from this group, send email to
> >
django-users...@googlegroups.com <javascript:>.
> <
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 view this discussion on the web visit
>
https://groups.google.com/d/msg/django-users/-/rP_BPdN3JHgJ.