I'm trying to make a single choice quiz (i.e. Choose one from 4 options). 
I'll populate the quiz (with 30 questions) depending upon what topic the 
user chooses. I'm made some models and forms, but when I try to migrate it 
says 

AttributeError: 'CharField' object has no attribute 'model'


I don't even know which model has problem. I've tried it in Django 1.9 
(with virtualenv) & 1.8, same error. I've tried both manage.py check & 
manage.py runserver and they all come up ok (with runserver saying I need 
to migrate). 

Python 2.7
Windows 7

Below are my models. Tell me if you require anything else. It's only 
partially made and I've taken long-cuts in many things, 1st I've to make 
the thing work.

from django.db import models
from django.template.defaultfilters import slugify
from django.conf import settings
from django.contrib.auth.models import User 


class UserProfile(models.Model):
 user = models.OneToOneField(settings.AUTH_USER_MODEL)
 topic = models.CharField(max_length=50, blank=True)


 def __unicode__(self):
 return self.user.username


class Subject(models.Model):
 subject_name = models.CharField(max_length=50)


 def __unicode__(self):
 return self.subject_name


class QuestionAnswer(models.Model):
 subject = models.ManyToManyField(Subject)
 question_text = models.TextField(max_length=150)
 option_w = models.CharField(max_length=75, blank=True, null=True)
 option_x = models.CharField(max_length=75, blank=True, null=True)
 option_y = models.CharField(max_length=75, blank=True)
 option_z = models.CharField(max_length=75, blank=True)
 correct_answer = models.CharField(max_length=75, blank=False, default=None)
 on = models.BooleanField(default=True)


 def __unicode__(self):
 return self.id


 class Meta:
 app_label = 'QuestionAnswer'
 verbose_name='Question'
 verbose_name_plural = 'Questions'


class QuizAttempt(models.Model):
 username = models.ManyToManyField(User)
 subject = models.ManyToManyField(Subject)
 slug = models.SlugField(unique=False)
 datetime = models.DateTimeField(auto_now_add=True)
 questions_included = models.ForeignKey(models.QuestionAnswer)
 correctly_answered_questions = models.IntegerField()
 total_marks = models.IntegerField()


 class Meta:
 verbose_name='Quiz'
 verbose_name_plural = 'Quizzes'


 def save(self, *args, **kwargs):
 self.slug = slugify(self.username +' ' +  self.subject + ' ' + self.
datetime.month +' ' +  self.datetime.year)
 super(QuizAttempt, self).save(*args, **kwargs)


 @property
 def correct_answer_count(self):
    return self._correct_answer_count

 def __unicode__(self):
 return "Quiz ID is {}".format(self.id)
 return "The quiz was taken by {} on {}".format(self.username, self.topic)
 return "The quiz was taken on {}".format(self.datetime)



-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/026c316a-5d41-4623-916b-354c96041e42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to