tags:

views:

22

answers:

1

Hi,
In my application I have a model that looks like this:

class Talk(models.Model):
    title = models.CharField(max_length=200, primary_key=True)
    speaker = models.CharField(max_length=200)
    date_of_talk = models.DateField('date_of_talk')
    def __unicode__(self):
        return self.title

class Member(models.Model):
    name = models.CharField(max_length=200)
    telephone_number = models.CharField(max_length=200)
    email_address = models.CharField(max_length=200)
    membership_type = models.CharField(max_length=1, choices=MEMBERSHIP_TYPES)
    membership_number = models.CharField(max_length=200, primary_key=True)
    def __unicode__(self):
        return self.name    
class Event_Attendance(models.Model):
    talk = models.ForeignKey('Talk')
    membersAttended = models.ForeignKey('Member')  
    def __unicode__(self):
    return '%s attended %s' %(unicode(self.membersAttended), unicode(self.talk))

And I want to be able to pull out all the results from the Event_Attendance model when i input a talk. This is so that i can get the names of the people that attended it. Every thing that I have tried has failed such as:

 a = Event_Attendance(talk="Meteors")

Has anyone else got any ideas?
Thanks in Advance,
Dean

+1  A: 

I think members_attended field in your EventAttendance model would be better as a ManyToManyField

class EventAttendance(models.Model):
    talk = models.ForeignKey(Talk)
    members_attended = models.ManyToManyField(Member)

That would make it easy to get the information you want.

chefsmart
I should also use through as i am managing the table "manually"
Dean