ManyToMany problem
Hi,
I have a problem with accessing items using ManyToMany relationship.
Here is a sample from shell:
>>> parts = Event.objects.all()[0].participants.all()
>>> parts
[<Participant: P1>, <Participant: P2>]
>>> parts[0]
<Participant: P2>
>>> parts[1]
<Participant: P2>
>>> for p in parts:
... print p
...
P1
P2
I cant figure out why accessing parts[0] and parts[1] gives the same
result, but loop works.
Code:
class Event(models.Model):
...
participants = models.ManyToManyField(Participant,
through='EventParticipant')
class EventParticipant(models.Model):
...
participant = models.ForeignKey(Participant)
event = models.ForeignKey(Event,
related_name="event_participants")
There is also a Participant class with nothing special inside. All
class have __unicode__ method to return name of the event/participant.
I'm still learning django, so any help will be apreciated :D
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home