ManyToMany problems

2 views
Skip to first unread message

plisk

unread,
Nov 22, 2005, 9:58:13 AM11/22/05
to Django users
Hi,

Based on the following model

from django.models.auth import User

class PolicyCategory(meta.Model):
name = meta.CharField(maxlength=100);
users = meta.ManyToManyField(User, blank=True)

class META:
db_table = 'intranet_policies'
module_name = 'policies'
verbose_name_plural = 'policies'

i'm trying to get list of users with field lookups

>>> from django.models.auth import users
>>> from django.models.intranet import policycategories
>>>
>>> pc = policycategories.get_object(pk=1)
>>> pc.get_user_list(groups__name__exact='Tech')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/django/utils/functional.py",
line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
TypeError: method_get_many_to_many() got an unexpected keyword argument
'groups__name__exact'

Seems like get_xxx_list in many to many relations doesn't support
lookups ? Or is this a bug ? Cos if i do the following

>>> u = users.get_object(pk=1)
>>> u.get_intranet_policycategory_list(name__exact='Billing')
[Billing]

everything is working fine. Any hints on this, maybe i'm missing
something ?

Adrian Holovaty

unread,
Nov 22, 2005, 11:44:25 AM11/22/05
to django...@googlegroups.com
On 11/22/05, plisk <rot...@gmail.com> wrote:
> >>> pc.get_user_list(groups__name__exact='Tech')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.4/site-packages/django/utils/functional.py",
> line 3, in _curried
> return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
> morekwargs.items()))
> TypeError: method_get_many_to_many() got an unexpected keyword argument
> 'groups__name__exact'
>
> Seems like get_xxx_list in many to many relations doesn't support
> lookups ? Or is this a bug ?

Does the following work?

"""
from django.models.auth import users
users.get_list(groups__name__exact='Tech')
"""

Behind the scenes, pc.get_user_list() is just a wrapper around
users.get_list(). So a good way to test things in this case is to use
users.get_list(). If the parameters aren't valid there, they won't be
valid in pc.get_user_list().

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

rotmer

unread,
Nov 22, 2005, 12:03:19 PM11/22/05
to django...@googlegroups.com
Adrian Holovaty wrote:
> On 11/22/05, plisk <rot...@gmail.com> wrote:
>>>>> pc.get_user_list(groups__name__exact='Tech')
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>> File "/usr/lib/python2.4/site-packages/django/utils/functional.py",
>> line 3, in _curried
>> return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
>> morekwargs.items()))
>> TypeError: method_get_many_to_many() got an unexpected keyword argument
>> 'groups__name__exact'
>>
>> Seems like get_xxx_list in many to many relations doesn't support
>> lookups ? Or is this a bug ?
>
> Does the following work?
>
> """
> from django.models.auth import users
> users.get_list(groups__name__exact='Tech')
> """

Yes, this one works fine. And just pc.get_user_list() also works, but
with arguments it fails. Tried plain
pc.get_user_list(username__exact='admin') and got the same error. By the
way, rev 1350.

> Behind the scenes, pc.get_user_list() is just a wrapper around
> users.get_list(). So a good way to test things in this case is to use
> users.get_list(). If the parameters aren't valid there, they won't be
> valid in pc.get_user_list().

In users.get_list() everything works as it should..

plisk
Reply all
Reply to author
Forward
0 new messages