Hi all,

I need to create some kind of survey for my studies but I'm struggling with 
the models.py. I did read some tutorial on Django and I like it very much, 
but I'm no expert when it comes to database modellling. 

Here is my proposed models.py:

class User(models.Model):

    SEX =   (
        ('m','male'),
        ('f','female')
    )

    user_name = models.CharField(max_length=200)
    user_age = models.IntegerField()
    user_sex = models.CharField(max_length=1, choices=SEX)
    user_count_answers_given = models.IntegerField(default=0)

    def __unicode__(self):
        return self.user_name

# a Collection of Pictures
# a subset of Questions is chosen for each Collection
class Collection(models.Model):
    collection_name = models.CharField(max_length=200)

    def __unicode__(self):
        return self.collection_name


# an Picture is place into exactly one Collection
class Picture(models.Model):
    path = models.CharField(max_length=500)
    title = models.CharField(max_length=200)
    
    def __unicode__(self):
        return self.title


# a List of Questions like:
# - How much do you like this Picture?
# - Is there a girl or a boy in the Picture?
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    collection_enabled = models.ManyToManyField(Collection)

    def __unicode__(self):
        return self.question_text

# Have to save each answer for a specific Picture
# by a specific user and for a specific question
class Answer(models.Model):
    question = models.ForeignKey(Question)
    User = models.ForeignKey(User)
    Picture = models.ForeignKey(Picture)
    choice_value = models.IntegerField()
    timestamp = models.DateField(datetime.now())


Now the problem I have is with the Answer class in general. 
I want to create several Collections consisting of different pictures. Also 
I will have a list of questions. Not all questions should be enabled for 
each Collection, for example if I create a collection of pictures with no 
persons in the pictures, it doesn't make sense to ask the user if they see 
a girl or a boy in the picture. 
That is why I added this ManyToMany relationship in Question. I'm not sure 
if this is the correct way to do this. 

Let's assume that I enabled 3 Questions for a certain Collection of 
Pictures. Now I want to track the answers given by the Users. For some 
questions the answer should be select by a button labeled 'boy' or 'girl' 
whereas for likeability it should be selected using a radio button which 
ranges from 0 (don't like) to 7 (like it very much). 
Later on, I need to be able to see for each picture how many people 
selected which answer (10 people selected boy, 5 people girl and so on). 
Also I want to calculate an average score for likeability. I want to 
display this score directly after the user gave his input.
So I thought that I need additional fields in the Picture class to safe the 
average score, but what if my question list changes? Then I need to update 
the Picture class every time and add an additional field for each new 
question. That doesn't make sense. I would need something like a Decorator 
pattern - but I have no idea if this is possible in databases, or how to 
model it.

Can anyone please help me with this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddb89b0f-cc52-4696-a2c4-8b76fc7e917f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to