1 | from django.db import models
|
---|
2 |
|
---|
3 | class Subject(models.Model):
|
---|
4 | name = models.CharField(maxlength=40)
|
---|
5 |
|
---|
6 | class Course(models.Model):
|
---|
7 | name = models.CharField(maxlength=40)
|
---|
8 | subject = models.ForeignKey(Subject)
|
---|
9 | class Meta:
|
---|
10 | ordering = ["subject"]
|
---|
11 |
|
---|
12 | class Class(models.Model):
|
---|
13 | course = models.ForeignKey(Course)
|
---|
14 | name = models.CharField(maxlength = 40)
|
---|
15 |
|
---|
16 | class Meta:
|
---|
17 | ordering = ["course"]
|
---|
18 |
|
---|
19 |
|
---|
20 | __test__ = {'API_TESTS':"""
|
---|
21 | >>> s = Subject(name='Web Apps')
|
---|
22 | >>> s.save()
|
---|
23 | >>> c = Course(name='Djangology', subject=s)
|
---|
24 | >>> c.save()
|
---|
25 | >>> cl = Class(course=c, name='Django 101')
|
---|
26 | >>> cl.save()
|
---|
27 | >>> Class.objects.all().order_by('course')
|
---|
28 | [<Class: Class object>]
|
---|
29 | """}
|
---|