Fixing recommendations from pylint

This commit is contained in:
2013-08-25 20:16:20 +10:00
parent 423101e829
commit 5ab0b8c837
6 changed files with 57 additions and 13 deletions

View File

@@ -1,7 +1,15 @@
"""
Defines the models that that Django application uses
"""
from django.db import models
class CommonInfo(models.Model):
"""
Common base class for models that need a name and active field. It is
intended to be an abstract class.
"""
name = models.CharField(max_length=100)
active = models.BooleanField(default=True)
@@ -9,16 +17,27 @@ class CommonInfo(models.Model):
return self.name
class Meta:
"""
Declare the class as abstract
"""
abstract = True
class Category(CommonInfo):
"""
Contains the details for a category of samples. Categories have a parent
category field to another category which creates a tree structure.
"""
parent = models.ForeignKey('self', blank=True, null=True,
on_delete=models.SET_NULL,
related_name='children')
class Sample(CommonInfo):
"""
The definition of a model itself. The model_filename is the path relative
to the models directory.
"""
model_filename = models.CharField(max_length=1000)
description = models.CharField(max_length=2000, default='', blank=True,
null=True)
@@ -27,10 +46,16 @@ class Sample(CommonInfo):
class Question(models.Model):
"""
The definition of a multiple choice question, associated with a Sample
"""
text = models.CharField(max_length=2000)
sample = models.ForeignKey(Sample, related_name='questions')
def correct_answers(self):
"""
Return a list of correct answers to the question
"""
return self.answers.filter(correct=True)
def __unicode__(self):
@@ -38,6 +63,9 @@ class Question(models.Model):
class Answer(models.Model):
"""
The definition of an answer to a Question
"""
text = models.CharField(max_length=2000)
correct = models.BooleanField(default=False)
question = models.ForeignKey(Question, related_name='answers')