Generic ManyToMany Functionality

9 views
Skip to first unread message

Dave Sullivan

unread,
Oct 12, 2007, 5:05:26 PM10/12/07
to django-d...@googlegroups.com
Hey All,

Google and trac both show nothing on this kind of functionality. I see that
contenttypes work like a Generic ForeignKey (many-to-one) but I don't see
anything about ManyToMany.

Is there any work being done by anyone on this kind of feature? I have some of
the details in mind, and if it isn't being worked on by anyone else, I had
planned on starting work on it.

Basically, the concept is that generic m2m relations would be no more
difficult than standard m2m relations:

class MyModel(models.Model):
content = models.GenericManyToManyField()

The content field would work like any other m2m field:

>>> m = MyModel()
>>> m2 = MyOtherModel()
>>> m3 = MyThirdModel()

>>> m.content.add(m2)
>>> m.content.add(m3)
>>> m.content
[<model 'MyOtherModel'>, <model 'MyThirdModel'>]

Is anyone else working on something like this? Thoughts?

--
Dave Sullivan
da...@dave-sullivan.com
647-235-0328

Jacob Kaplan-Moss

unread,
Oct 12, 2007, 5:09:09 PM10/12/07
to django-d...@googlegroups.com
On 10/12/07, Dave Sullivan <demsu...@gmail.com> wrote:
> Google and trac both show nothing on this kind of functionality. I see that
> contenttypes work like a Generic ForeignKey (many-to-one) but I don't see
> anything about ManyToMany.
>
> Is there any work being done by anyone on this kind of feature? I have some of
> the details in mind, and if it isn't being worked on by anyone else, I had
> planned on starting work on it.

It's on my todo list -- I'm gonna need it for a project coming up in a
couple of months, at least -- but of course if you wanna take a crack
at it I'd love to let someone else do the work :)

Jacob

Dave

unread,
Oct 12, 2007, 5:16:18 PM10/12/07
to Django developers

On Oct 12, 5:09 pm, "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
wrote:

Thanks, I'd love to take a crack at it. I'll keep you posted about my
progress. Is there anything I need to do in terms of setting up a
project like this?
Post details on DjangoBranches and set up a branch on my own server,
or...?

Jacob Kaplan-Moss

unread,
Oct 12, 2007, 5:59:31 PM10/12/07
to django-d...@googlegroups.com
On 10/12/07, Dave <demsu...@gmail.com> wrote:
> Is there anything I need to do in terms of setting up a
> project like this?

It's not really a big deal -- should only be a small amount of code
(but writing the *right* code is the trick). I'd just do it as a patch
against django.contrib.contettpyes.

Myself, I use Mercurial and Mercurial Queues to manage patches of this
nature; some friends of mine use Git for the same purpose, and others
just use plain old SVN working dirs. YMMV, of course :)

Jacob

Dave

unread,
Oct 12, 2007, 10:10:55 PM10/12/07
to Django developers
On Oct 12, 5:59 pm, "Jacob Kaplan-Moss" <jacob.kaplanm...@gmail.com>
wrote:

> It's not really a big deal -- should only be a small amount of code


> (but writing the *right* code is the trick). I'd just do it as a patch
> against django.contrib.contettpyes.

Yeah, I suppose it would be relatively small. The way I had in mind
was to create a GenericManyToManyField and a
GenericManyRelationManager. I think that's all that would be
required...

Reply all
Reply to author
Forward
0 new messages