Populating a list in a form based on a relationship
Hi all,
I'm new to django/python. I have been looking through the docs since
several days but cannot get it to work. This is probably some common
stuff to handle.
Here's the situation:
My app should display a form based on the Report model. A Report has
several fields (reference, na, items) A Report can contain several
items. The items are defined and to be found in the model Item. Till
here I got it working.
Now, the tricky part for me is the following:
A company can make its own item collections. An item collection has a
name, a company (fk to Company model), and a list of items (many to
many relationship to Item model, using a through attribute because
that relation needs to store more information)
So, how can I get the Report form to display the items (in a multiple
select menu) that are part of an item collection. I don't want to
display the whole item list as it is working now.
In the following code you'll find my models.py and views.py:
http://dpaste.com/702880/
I tried to replace the many to many relationship in the report model
to ItemCollection instead of Item, but then it displays the names of
my different ItemCollections which is not the desired result.
To make things clear, a Report is not necesarily related to an
ItemCollection. The ItemCollection is related to a Company. The Report
is made/encoded by a Company. The company selects which items go into
that report.
Based on the company I pass as an argument, the form should get the
list of Items from ItemCollections. I suppose this has to be done in
the view, but I can't get my head around it.
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home