parts/django/tests/regressiontests/admin_widgets/models.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from django.db import models
       
     2 from django.contrib.auth.models import User
       
     3 
       
     4 class MyFileField(models.FileField):
       
     5     pass
       
     6 
       
     7 class Member(models.Model):
       
     8     name = models.CharField(max_length=100)
       
     9     birthdate = models.DateTimeField(blank=True, null=True)
       
    10     gender = models.CharField(max_length=1, blank=True, choices=[('M','Male'), ('F', 'Female')])
       
    11 
       
    12     def __unicode__(self):
       
    13         return self.name
       
    14 
       
    15 class Band(models.Model):
       
    16     name = models.CharField(max_length=100)
       
    17     members = models.ManyToManyField(Member)
       
    18 
       
    19     def __unicode__(self):
       
    20         return self.name
       
    21 
       
    22 class Album(models.Model):
       
    23     band = models.ForeignKey(Band)
       
    24     name = models.CharField(max_length=100)
       
    25     cover_art = models.FileField(upload_to='albums')
       
    26     backside_art = MyFileField(upload_to='albums_back', null=True)
       
    27 
       
    28     def __unicode__(self):
       
    29         return self.name
       
    30 
       
    31 class HiddenInventoryManager(models.Manager):
       
    32     def get_query_set(self):
       
    33         return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
       
    34 
       
    35 class Inventory(models.Model):
       
    36    barcode = models.PositiveIntegerField(unique=True)
       
    37    parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
       
    38    name = models.CharField(blank=False, max_length=20)
       
    39    hidden = models.BooleanField(default=False)
       
    40 
       
    41    # see #9258
       
    42    default_manager = models.Manager()
       
    43    objects = HiddenInventoryManager()
       
    44 
       
    45    def __unicode__(self):
       
    46       return self.name
       
    47 
       
    48 class Event(models.Model):
       
    49     band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0))
       
    50     start_date = models.DateField(blank=True, null=True)
       
    51     start_time = models.TimeField(blank=True, null=True)
       
    52     description = models.TextField(blank=True)
       
    53     link = models.URLField(blank=True)
       
    54     min_age = models.IntegerField(blank=True, null=True)
       
    55 
       
    56 class Car(models.Model):
       
    57     owner = models.ForeignKey(User)
       
    58     make = models.CharField(max_length=30)
       
    59     model = models.CharField(max_length=30)
       
    60 
       
    61     def __unicode__(self):
       
    62         return u"%s %s" % (self.make, self.model)
       
    63 
       
    64 class CarTire(models.Model):
       
    65     """
       
    66     A single car tire. This to test that a user can only select their own cars.
       
    67     """
       
    68     car = models.ForeignKey(Car)