Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 7, 2005 10:16:43

q.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Adding ManyToMany relationships


Sorry - I'm probably doing something silly here...

I have a 'Meeting' object which has a list of required attendees and a
list of optional attendees. The admin interface works fine, but I'm
stuck when it comes to manipulating these relationships in my own code.


The attendees are Users. So I have:

class Meeting(meta.Model):
...
req_parts = meta.ManyToManyField(User,
verbose_name = "required participants",
help_text = "People who must be there",
singular = "reqparts",
blank = True)
opt_parts = meta.ManyToManyField(User,
verbose_name = "optional participants",
help_text = "People who could be there",
singular = "optparts",
blank = True)

But how, in my own code, should I add a User to one of these lists?
The Meeting object has
get_reqparts_list() and get_optparts_list(), and I was hoping it might
have add_reqparts() as with ForeignKeys, but it only has
set_req_parts(), which seems to take a list of ids.

Is that the right way to do it? Doesn't feel right, but I couldn't find
any docs...

Many thanks....

Offline

#2 Dec. 7, 2005 10:19:18

q.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Adding ManyToMany relationships


Oh, and I'm using the latest svn trunk.

Offline

#3 Dec. 7, 2005 13:35:54

q.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Adding ManyToMany relationships


OK, I've found the code, and it looks as if set_FOOs() does intelligent
things about only updating the *changes* to the list of object IDs.
I'll use that for now.

Add and Delete methods would be nice though, as would something that
takes objects instead of IDs. Seems more Djangoesque. (Is that a
word?)

Offline

#4 Dec. 8, 2005 13:12:27

Jason F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Adding ManyToMany relationships


On Wed, 2005-12-07 at 05:35 -0800, quentinsf wrote:
> OK, I've found the code, and it looks as if set_FOOs() does intelligent
> things about only updating the *changes* to the list of object IDs.
> I'll use that for now.
>
> Add and Delete methods would be nice though, as would something that
> takes objects instead of IDs. Seems more Djangoesque. (Is that a
> word?)

I've also been missing add/delete methods. The app I'm writing/using
uses a ManyToMany relationship to keep track of what articles each user
has read. Adding to this list is a little slow, at least partly because
the whole list must be fetched and updated before set_FOOs() gets
called.

--
+----------------------------------------------------------------+
| Jason F. McBrayer |
| "If you wish to make Pythocles wealthy, don't give him more |
| money; rather, reduce his desires." -- Epicurus |

Offline

Board footer

Moderator control

Enjoy the 22nd of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support