Hello fellow Django users,
I have a model with a m2m relationship to self (think tickets that
optionally depend on one
or more tickets) and I want the the UI of the admin app add/change
pages to exclude the
item itself from the possible choices of tickets the user can select
it to depend on.
dependencies = models.ManyToManyField('self', symmetrical=False,
related_name='blocked_items', verbose_name=_('Depends on'), null=True,
blank=True)
I'm trying to use limit_choices_to for that, but I can' t find a way
to express what I want;
there is not <fieldname>__ne field lookup expression in Django. I can't use the
exclude(**kwargs) method because the limit_choices_to only accepts
dictionaries of the
form {<field_lookup spec>: <constraint value>, ...} or Q objects.
Trying to use a handful of variations with the (undocumented?) QNot
object type don' t
work either, the model validation stops with these kind of errors
both
limit_choices_to=QNot=(id_exact=self.id)
limit_choices_to=QNot=(pk=self.id)
give
File ".../models.py", line 36, in Item
dependencies = models.ManyToManyField('self', symmetrical=False,
related_name='blocked_items', verbose_name=_('Depends on'), null=True,
blank=True, limit_choices_to=QNot(id__exact=self.id))
NameError: name 'self' is not defined
limit_choices_to=QNot=(id__exact=id) gives
File ".../models.py", line 36, in Item
dependencies = models.ManyToManyField('self', symmetrical=False,
related_name='blocked_items', verbose_name=_('Depends on'), null=True,
blank=True, limit_choices_to=QNot(id__exact=id))
TypeError: __init__() got an unexpected keyword argument 'id__exact'
limit_choices_to=QNot=(pk=id) gives
File ".../models.py", line 36, in Item
dependencies = models.ManyToManyField('self', symmetrical=False,
related_name='blocked_items', verbose_name=_('Depends on'), null=True,
blank=True, limit_choices_to=QNot(pk=id))
TypeError: __init__() got an unexpected keyword argument 'pk'
ideas?
TIA
--
Ramiro Morales
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---