2010-01-27 21:30:29 +08:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class User(models.Model):
|
|
|
|
username = models.CharField(max_length=100)
|
|
|
|
email = models.EmailField()
|
|
|
|
|
|
|
|
|
|
|
|
class UserProfile(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
user = models.OneToOneField(User, models.CASCADE)
|
2010-01-27 21:30:29 +08:00
|
|
|
city = models.CharField(max_length=100)
|
|
|
|
state = models.CharField(max_length=2)
|
|
|
|
|
|
|
|
|
|
|
|
class UserStatResult(models.Model):
|
|
|
|
results = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
|
|
|
|
class UserStat(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
user = models.OneToOneField(User, models.CASCADE, primary_key=True)
|
2010-01-27 21:30:29 +08:00
|
|
|
posts = models.IntegerField()
|
2015-07-22 22:43:21 +08:00
|
|
|
results = models.ForeignKey(UserStatResult, models.CASCADE)
|
2010-01-27 21:30:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class StatDetails(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
base_stats = models.OneToOneField(UserStat, models.CASCADE)
|
2010-01-27 21:30:29 +08:00
|
|
|
comments = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class AdvancedUserStat(UserStat):
|
2010-03-20 23:02:59 +08:00
|
|
|
karma = models.IntegerField()
|
2010-02-24 03:24:27 +08:00
|
|
|
|
2012-11-10 02:21:46 +08:00
|
|
|
|
2010-02-24 03:24:27 +08:00
|
|
|
class Image(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
|
|
|
|
class Product(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
image = models.OneToOneField(Image, models.SET_NULL, null=True)
|
2012-11-10 02:21:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Parent1(models.Model):
|
|
|
|
name1 = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
|
|
|
|
class Parent2(models.Model):
|
|
|
|
# Avoid having two "id" fields in the Child1 subclass
|
|
|
|
id2 = models.AutoField(primary_key=True)
|
|
|
|
name2 = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
|
|
|
|
class Child1(Parent1, Parent2):
|
|
|
|
value = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class Child2(Parent1):
|
2015-07-22 22:43:21 +08:00
|
|
|
parent2 = models.OneToOneField(Parent2, models.CASCADE)
|
2012-11-10 02:21:46 +08:00
|
|
|
value = models.IntegerField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-11-10 02:21:46 +08:00
|
|
|
class Child3(Child2):
|
|
|
|
value3 = models.IntegerField()
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2012-11-10 02:21:46 +08:00
|
|
|
class Child4(Child1):
|
|
|
|
value4 = models.IntegerField()
|
2016-12-13 22:06:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
class LinkedList(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
previous_item = models.OneToOneField(
|
|
|
|
'self', models.CASCADE,
|
|
|
|
related_name='next_item',
|
|
|
|
blank=True, null=True,
|
|
|
|
)
|