I found exactly what I was looking for in the docs,
http://www.djangoproject.com/documentation/0.96/model-api/#many-to-one-relationships.


Using limit_choices_to={column_in_related_table_as_string : value_as_string}
did exactly what I was looking for.

Hope this helps someone else.

Darren

On Wed, Apr 14, 2010 at 10:29 PM, darren <backdoc...@gmail.com> wrote:

> I have two model classes that are related via a foreign key.  However,
> that's not limiting my results enough.  I'm getting too many choices in the
> drop down list of choices in the admin interface.  I'm trying to figure out
> where I should filter this.  If I was writing my own sql, I'd limit my
> results in the WHERE.  And, my query would look like this:
>
>   SELECT * FROM person a, stat b
>   WHERE
>     a.name = b.name and
>     a.type = 'Player'
>
> My model classes are like:
>
>   Class Person(models.Model):
>     name=charField(.....)
>     type = choiceField(choices=(('Player', 'Player'), ('Sibling',
> 'Sibling'),('Coach', 'Coach')))
>
>   Class Stat(models.Model):
>     name = foreignKey(Person, to_field=name)
>     stats = charField(....)
>
> The key here is that I want to limit my drop down list to only 'Players".
>  Since this is not a view that I've written, I'm not sure how to approach
> this.  I was figuring that if I wrote the view, I would do something like
> this (warning, I may not have that syntax quite right):
>
>     players = Stat.objects.filter(Person__type='Player')
>
> TIA,
> Darren
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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