Friday, June 1, 2012

Django/Python Circular model reference

Hi all,

I am trying to create two django models that reference each other. 1
model is a question and the other model is an answer. Each answer has
a question, and each question has an answer. I cant seem to get it to
work without error. Below is the code.

from django.db import models
........

class Answer(models.Model):
title = models.CharField(max_length = 50)
answer = models.CharField(max_length = 400)
customer_response = models.ManyToManyField(Question)
def __unicode__(self):
return self.title

class Question(models.Model):
title = models.CharField(max_length = 50)
response = models.CharField(max_length = 400)
answer = models.ManyToManyField(Answer)
def __unicode__(self):
return self.title



Thanks!

--
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.

No comments:

Post a Comment