Hi Manuel!
Am 07.10.2007 um 15:19 schrieb Manuel Meyer:
> But what I want to have is, that any Category - that is parent for
> any Project - cannot be parent for any Category and reverse.
>
> Is it possible, to filter the entries in the admins ForeingKey-list?
> Got any hint for me?
You can use the "limit_choices_to" argument [1] with a field lookup
to filter the options of a ForeignKey field. Keep in mind that a
lookup can be reverse [2] and relationship spanning [3].
For example you can achieve a simple filtered list of parent
categories with the following model:
class Category(models.Model):
title = models.CharField(maxlength=50)
parent = models.ForeignKey('self', limit_choices_to =
{'parent__exact': None}, blank=True)
You are able to create a parent category just by leaving the "parent"
field empty. The category field will only contain categories which
have no parents when you add more categories.
I think you can get even more functionality by writing your own
validator [4] and passing it with the "validator_list" argument, but
I have no idea about the destiny of validators considering the
newforms-admin branch.
Hope that helps,
Jannis
1: http://www.djangoproject.com/documentation/model-api/#many-to-one-
relationships
2: http://www.djangoproject.com/documentation/models/reverse_lookup/
3: http://www.djangoproject.com/documentation/db-api/#lookups-that-
span-relationships
4: http://www.djangoproject.com/documentation/forms/#validators
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---