ManyToMany relationship

20 views
Skip to first unread message

venkat

unread,
Aug 23, 2015, 3:34:26 PM8/23/15
to Django users
I have two models as follows


class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
date_of_birth = models.DateField()
height = models.IntegerField()
def __unicode__(self):
return '%s %s' %(self.first_name, self.last_name)

class Movie(models.Model):
name = models.CharField(max_length = 30)
language = models.CharField(max_length=30)
release_date = models.DateField()
image = models.ImageField(upload_to = 'images')
cast = models.ManyToManyField(Person)
directors = models.ManyToManyField(Person)
def __unicode__(self):
return self.name


cast and directors having maytomany relationship with person is causing an error.
How can i overcome this??


Thanks,
Venkateswara Reddy,

James Schneider

unread,
Aug 23, 2015, 3:38:24 PM8/23/15
to django...@googlegroups.com

What is the error and/or traceback?

-James

Carlos A. Carnero Delgado

unread,
Aug 23, 2015, 3:50:05 PM8/23/15
to django...@googlegroups.com

El ago. 23, 2015 3:34 PM, "venkat" <eswa...@gmail.com> escribió:
>
> How can i overcome this??
>

I think you should be using the related_name property in the ManyToMany fields of the model. Giving different names, of course, since that maybe the cause of your problems. It is documented, BTW.

HTH,
Carlos.

Reply all
Reply to author
Forward
0 new messages