Skip to content

Instantly share code, notes, and snippets.

@renovatorruler
Created May 4, 2010 17:20
Show Gist options
  • Save renovatorruler/389687 to your computer and use it in GitHub Desktop.
Save renovatorruler/389687 to your computer and use it in GitHub Desktop.
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Question(models.Model):
'''
Model to store Question text and the user who added it. References to the contrib.auth's user model
'''
text=models.TextField()
addedBy=models.ForeignKey(User)
def __unicode__(self):
return self.text
class Meta:
ordering = ['text']
class Answer(models.Model):
'''
Model tostore Answer text and question to whom this answer is associated to
'''
text=models.TextField()
question=models.ForeignKey(Question)
def __unicode__(self):
return self.text
class Relationshipdna(models.Model):
'''
When a user answers a question this must be stored somewhere, this one creates a many to many relationship using the
QuestionAnswer model to store the actual answer.
'''
user=models.ForeignKey(User)
questions=models.ManyToManyField(Question,through='QuestionAnswer')
def __unicode__(self):
return self.user.username
class AnswerValue(models.Model):
'''
An answer can have relevance from more or less important to a user
'''
value=models.CharField(max_length=30)
def __unicode__(self):
return self.value
class QuestionAnswer(models.Model):
'''
Model which stores a question, and the answer a user picked.
'''
question=models.ForeignKey(Question)
relationshipdna=models.ForeignKey(Relationshipdna)
answer=models.ForeignKey(Answer)
answervalue=models.ForeignKey(AnswerValue)
def __unicode__(self):
return u'%s-%s(%s)' % (self.question.text,self.answer.text,self.answervalue.value)
class UserProfile(models.Model):
'''
UserProfile Model
'''
user=models.ForeignKey(User, unique=True)
zodiac=models.TextField()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment