I am working on this.  I think it is not simple.  The queryset for the
forms in the change_list view are created at a point in the code where
there is no info on what the actual object associated with that form
is.  There is no simple way (ie, an arg or callback) to make a foreign
key field in the change_list view have a queryset that is specific to
that item. I think you have to use an ajax request to modify the
queryset on the fly.  The approach I am trying to take is that when
the user does a mouse-down on the foreign key field, it sends a
request to the server to get the possible values for the foreign key.
I'm not yet sure what to do about the initial value.  For example, if
I start with a queryset that is empty, then the selected value (in the
case where the object already has a value) does not show up.
Alternately, I don't want my queryset to start out with all objects,
because in my case that number is too large (would be all users in the
system).  So perhaps I will need a special ajax get that sets all
intial values for the query set ... I am not sure.  Anyway, I don't
have code working yet, but I just posted a long question with the code
that I have, at:

http://groups.google.com/group/django-users/browse_frm/thread/8383074770a19a61

Maybe I'm heading down the wrong path, it seems complex, I really am
not sure...

Margie

On May 14, 4:54 pm, Jamie <utkja...@gmail.com> wrote:
> Have you found a solution for this? I'm surprised no one has at least
> responded that it is or is not possible.
>
> On Apr 9, 1:09 pm, Nicky Bulthuis <nic...@versatel.nl> wrote:
>
> > Hello Django Users,
>
> > I'm trying to learn Django as best as i can, however i've come to  
> > problem which i hope someone can help me with.
>
> > I have two models, Release and OTAP.
>
> > A Release is a reference to a file and linked to an OTAP. An OTAP can  
> > have a Release for each of the 4 environments. I've modeled this as  
> > below:
>
> > class Release(models.Model):
>
> >         name = models.CharField(max_length=128, unique=True, )
> >         path = models.CharField(max_length=512, )
>
> >         otap = models.ForeignKey('OTAP')
>
> > class OTAP(models.Model):
>
> >         name = models.CharField(max_length=128, unique=True, )
>
> >         o_release = models.ForeignKey(Release, 
> > verbose_name="O-Environment",  
> > related_name='o_release', null=True, blank=True)
> >         t_release = models.ForeignKey(Release, 
> > verbose_name="T-Environment",  
> > related_name='t_release', null=True, blank=True)
> >         a_release = models.ForeignKey(Release, 
> > verbose_name="A-Environment",  
> > related_name='a_release', null=True, blank=True)
> >         p_release = models.ForeignKey(Release, 
> > verbose_name="P-Environment",  
> > related_name='p_release', null=True, blank=True)
>
> > This all works in the admin interface, i can select Releases for each  
> > OTAP i have for each of the 4 environments. However i would like to  
> > limit the choices of the environments to just those releases that  
> > belong to that OTAP. I've tried to work with the 'limit_choices_to'  
> > from the ForeignKey, but i've had no luck so far. I've tried to limit  
> > the Release to the otap field but i can't seem to figured out how to  
> > select the 'self' of OTAP.
>
> > So my question is: how do i limit the choices for each environment to  
> > just those release belonging to the OTAP?
>
> > I hope someone can point me in the right direction.
>
> > Regards,
> > Nick
--~--~---------~--~----~------------~-------~--~----~
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