Hello,

  I have many models which have a foreign key to a main model. Eg:

class MainModel:
  ..
  ..

class VariousModels:
  main = ForeignKey(MainModel)
  ..
  ..

Now, these VariousModels sometimes have links to each other in the
form of ForeignKey or ManyToMany.  I need to limit these ForeignKey
and ManyToMany in various ModelForms to only display other
VariousModels which share the same MainModel in common.  Here is what
I tried to do and it didn't work:

item = models.ForeignKey(Item, limit_choices_to={'main__pk':main},
blank=True, null=True)

I attempted different versions of this on the actual model.  I am now
looking into how I can perform this using a ModelForm instead of
placing the limits on the actual model.  I'm not sure if this will
work, as the ModelForm's QuerySet for the choiceField cannot be
changed dynamically during runtime, or can it?

Basically, I am creating a multi-user/multi-section application.  The
main model described above is a section which a user creates and
manages.  The user should only see choices in the forms for objects
associated with the current section they are editing.

Perhaps I am going about this entirely wrong and this should be
implemented in a different form, such as a permission.

Any ideas on how this can be done would be very helpful, thanks.

-- 
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