I would like to design a model for an online private school in Django. It focuses on relation among Students
, Tutors
and Courses
.
The most important factor that should be considered is that Students
can add and Tutors
can create courses.
I'd like to extend built-in Djano's "User" and extend its functionality.
I have designed a very draft model like this:
from django.db import models
from django.contrib.auth.models import User , Group
from django.utils.translation import ugettext as _
class Course(models.Model):
name = models.CharField(max_length = 70)
slug = models.SlugField()
created = models.DateTimeField(auto_now = True)
updated = models.DateTimeField(auto_now_add = True)
description = models.TextField()
student = models.ManyToManyField('Student' , null = True, blank = True, related_name = _('Student courses'))
tutor = models.ManyToManyField('Tutor' , null = True, blank = True , related_name = _('Tutor courses'))
def __unicode__(self):
return self.name
class Meta:
verbose_name = ('course')
verbose_name_plural = ('courses')
class Student(models.Model):
user = models.ForeignKey(User , blank = True)
#photo = models.ImageField(_('photo'), upload_to='photos/', blank=True)
class Tutor(models.Model):
user = models.ForeignKey(User , blank = True)
#photo = models.ImageField(_('photo'), upload_to='photos/', blank=True)
First of all: is it a correct approach? I'd like to have User, so I can use it in View and Template layers.
Second, how can I query that which student has got which courses?
Thank you beforehand ..
Rather than have a Student
and Tutor
model I would look at using the user profiles supported by Django. Also the auth module has a fairly complete permissions model, that you could use instead of creating your own system to allow only some users to create courses.