parts/django/tests/regressiontests/select_related_onetoone/models.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from django.db import models
       
     2 
       
     3 
       
     4 class User(models.Model):
       
     5     username = models.CharField(max_length=100)
       
     6     email = models.EmailField()
       
     7 
       
     8     def __unicode__(self):
       
     9         return self.username
       
    10 
       
    11 
       
    12 class UserProfile(models.Model):
       
    13     user = models.OneToOneField(User)
       
    14     city = models.CharField(max_length=100)
       
    15     state = models.CharField(max_length=2)
       
    16 
       
    17     def __unicode__(self):
       
    18         return "%s, %s" % (self.city, self.state)
       
    19 
       
    20 
       
    21 class UserStatResult(models.Model):
       
    22     results = models.CharField(max_length=50)
       
    23 
       
    24     def __unicode__(self):
       
    25         return 'UserStatResults, results = %s' % (self.results,)
       
    26 
       
    27 
       
    28 class UserStat(models.Model):
       
    29     user = models.OneToOneField(User, primary_key=True)
       
    30     posts = models.IntegerField()
       
    31     results = models.ForeignKey(UserStatResult)
       
    32 
       
    33     def __unicode__(self):
       
    34         return 'UserStat, posts = %s' % (self.posts,)
       
    35 
       
    36 
       
    37 class StatDetails(models.Model):
       
    38     base_stats = models.OneToOneField(UserStat)
       
    39     comments = models.IntegerField()
       
    40 
       
    41     def __unicode__(self):
       
    42         return 'StatDetails, comments = %s' % (self.comments,)
       
    43 
       
    44 
       
    45 class AdvancedUserStat(UserStat):
       
    46     karma = models.IntegerField()
       
    47 
       
    48 class Image(models.Model):
       
    49     name = models.CharField(max_length=100)
       
    50 
       
    51 
       
    52 class Product(models.Model):
       
    53     name = models.CharField(max_length=100)
       
    54     image = models.OneToOneField(Image, null=True)