Friday, June 1, 2012

Re: Django/Python Circular model reference

class Question(models.Model):
   title = models.CharField(max_length = 50)
   response = models.CharField(max_length = 400)
   parent = models.OneToOne('self', related_name='child', null=True)

   def __unicode__(self):
       return self.title

class Answer(models.Model):
   question = models.OneToOne(Question, related_name='answer')
   title = models.CharField(max_length = 50)
   answer = models.CharField(max_length = 400)
   def __unicode__(self):
       return self.title


On Fri, Jun 1, 2012 at 7:05 PM, Jak <jacob.wischnia@gmail.com> wrote:
Think of it kind of like a conversation.

Person A asks a question
new Q1 
Person B answers
new A1->Q1 
Person A asks another question
new Q2->Q1 
Person B gives a different answer.
new A2->Q2 

So for every question there could be an answer and for every answer
there could be another question

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