2010-01-27 13:30:29 +00: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 14:43:21 +00:00
|
|
|
user = models.OneToOneField(User, models.CASCADE)
|
2010-01-27 13:30:29 +00: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 14:43:21 +00:00
|
|
|
user = models.OneToOneField(User, models.CASCADE, primary_key=True)
|
2010-01-27 13:30:29 +00:00
|
|
|
posts = models.IntegerField()
|
2015-07-22 14:43:21 +00:00
|
|
|
results = models.ForeignKey(UserStatResult, models.CASCADE)
|
2010-01-27 13:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class StatDetails(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
base_stats = models.OneToOneField(UserStat, models.CASCADE)
|
2010-01-27 13:30:29 +00:00
|
|
|
comments = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class AdvancedUserStat(UserStat):
|
2010-03-20 15:02:59 +00:00
|
|
|
karma = models.IntegerField()
|
2010-02-23 19:24:27 +00:00
|
|
|
|
2012-11-09 18:21:46 +00:00
|
|
|
|
2010-02-23 19:24:27 +00:00
|
|
|
class Image(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
|
|
|
|
class Product(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2015-07-22 14:43:21 +00:00
|
|
|
image = models.OneToOneField(Image, models.SET_NULL, null=True)
|
2012-11-09 18:21:46 +00: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 14:43:21 +00:00
|
|
|
parent2 = models.OneToOneField(Parent2, models.CASCADE)
|
2012-11-09 18:21:46 +00:00
|
|
|
value = models.IntegerField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-11-09 18:21:46 +00:00
|
|
|
class Child3(Child2):
|
|
|
|
value3 = models.IntegerField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2012-11-09 18:21:46 +00:00
|
|
|
class Child4(Child1):
|
|
|
|
value4 = models.IntegerField()
|
2016-12-13 14:06:54 +00: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,
|
|
|
|
)
|