ManyToMany + through + using add, d

187 views
Skip to first unread message

pihentagy

unread,
Aug 14, 2008, 11:45:50 AM8/14/08
to Django users
Hi all!

I am playing with the new manytomany option with throgh, find in the
docs, that:
"""
# THIS WILL NOT WORK
>>> beatles.members.add(john)
# NEITHER WILL THIS
>>> beatles.members.create(name="George Harrison")
# AND NEITHER WILL THIS
>>> beatles.members = [john, paul, ringo, george]

Why? You can’t just create a relationship between a Person and a Group
- you need to specify all the detail for the relationship required by
the Membership table. The simple add, create and assignment calls
don’t provide a way to specify this extra detail.
"""
Ok, but what if the model Members has reasonable default values, so
one can assign a person to a group without extra info.

In my case, I just want to syncronize 2 databases, and I would like to
mark relationships, that are already synced. So, in my case, the
intermediate table contains a boolean, which defaults to false, and
will become true, when the data is synced.

Is there any chance add and create and other will work in the future
for this special case?

thanks
Gergo

Russell Keith-Magee

unread,
Aug 14, 2008, 7:44:39 PM8/14/08
to django...@googlegroups.com
On Thu, Aug 14, 2008 at 11:45 PM, pihentagy <pihe...@gmail.com> wrote:
>
> In my case, I just want to syncronize 2 databases, and I would like to
> mark relationships, that are already synced. So, in my case, the
> intermediate table contains a boolean, which defaults to false, and
> will become true, when the data is synced.
>
> Is there any chance add and create and other will work in the future
> for this special case?

I'll need to give it some more thought, but it's not an unreasonable
idea. I'd like to see a way to support add and create for
m2m-intermediates; the partial solution of allowing add/create if all
the non-FK fields have defaults or are NULLable would be one way of
approaching this.

However, it won't happen for v1.0 - at this point, we are pretty much
in feature freeze. Open a ticket so that the idea isn't forgotten; if
you want to try your hand at fixing it, we can see about getting this
fix in for v1.1.

Yours,
Russ Magee %-)

akaihola

unread,
Aug 28, 2008, 7:25:27 AM8/28/08
to Django users
I was just discussing this on the #django channel with Kuba, and we
couldn't think why the following syntax wouldn't be possible to
implement:

>>> beatles.members.add(john, paul, date_joined=date(1961, 1, 1))

It would be otherwise similar to a normal m2m, but all keyword
arguments would be used to initialize fields of the intermediary model.

akaihola

unread,
Aug 29, 2008, 2:40:39 AM8/29/08
to Django users
This looks like Gergo's ticket for his original request:
http://code.djangoproject.com/ticket/8334

Richard Ward

unread,
Aug 29, 2008, 8:09:28 AM8/29/08
to django...@googlegroups.com
It looks like the solution to this is in the newest release. Ref.
http://code.djangoproject.com/changeset/8136

Russell Keith-Magee

unread,
Aug 30, 2008, 1:31:39 AM8/30/08
to django...@googlegroups.com
On Fri, Aug 29, 2008 at 8:09 PM, Richard Ward <times...@gmail.com> wrote:
>
> It looks like the solution to this is in the newest release. Ref.
> http://code.djangoproject.com/changeset/8136

Richard - Gergo, Antti, and I are well aware of the m2m intermediate
change in [8136]. What we are discussing here is a possible extension
to allow use of the add() in m2m relations that have a through clause.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages