~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/regressiontests/admin_widgets/models.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import unicode_literals
2
 
 
3
 
from django.db import models
4
 
from django.contrib.auth.models import User
5
 
from django.utils.encoding import python_2_unicode_compatible
6
 
 
7
 
 
8
 
class MyFileField(models.FileField):
9
 
    pass
10
 
 
11
 
@python_2_unicode_compatible
12
 
class Member(models.Model):
13
 
    name = models.CharField(max_length=100)
14
 
    birthdate = models.DateTimeField(blank=True, null=True)
15
 
    gender = models.CharField(max_length=1, blank=True, choices=[('M','Male'), ('F', 'Female')])
16
 
 
17
 
    def __str__(self):
18
 
        return self.name
19
 
 
20
 
@python_2_unicode_compatible
21
 
class Band(models.Model):
22
 
    name = models.CharField(max_length=100)
23
 
    style = models.CharField(max_length=20)
24
 
    members = models.ManyToManyField(Member)
25
 
 
26
 
    def __str__(self):
27
 
        return self.name
28
 
 
29
 
@python_2_unicode_compatible
30
 
class Album(models.Model):
31
 
    band = models.ForeignKey(Band)
32
 
    name = models.CharField(max_length=100)
33
 
    cover_art = models.FileField(upload_to='albums')
34
 
    backside_art = MyFileField(upload_to='albums_back', null=True)
35
 
 
36
 
    def __str__(self):
37
 
        return self.name
38
 
 
39
 
class HiddenInventoryManager(models.Manager):
40
 
    def get_query_set(self):
41
 
        return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
42
 
 
43
 
@python_2_unicode_compatible
44
 
class Inventory(models.Model):
45
 
   barcode = models.PositiveIntegerField(unique=True)
46
 
   parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
47
 
   name = models.CharField(blank=False, max_length=20)
48
 
   hidden = models.BooleanField(default=False)
49
 
 
50
 
   # see #9258
51
 
   default_manager = models.Manager()
52
 
   objects = HiddenInventoryManager()
53
 
 
54
 
   def __str__(self):
55
 
      return self.name
56
 
 
57
 
class Event(models.Model):
58
 
    band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0))
59
 
    start_date = models.DateField(blank=True, null=True)
60
 
    start_time = models.TimeField(blank=True, null=True)
61
 
    description = models.TextField(blank=True)
62
 
    link = models.URLField(blank=True)
63
 
    min_age = models.IntegerField(blank=True, null=True)
64
 
 
65
 
@python_2_unicode_compatible
66
 
class Car(models.Model):
67
 
    owner = models.ForeignKey(User)
68
 
    make = models.CharField(max_length=30)
69
 
    model = models.CharField(max_length=30)
70
 
 
71
 
    def __str__(self):
72
 
        return "%s %s" % (self.make, self.model)
73
 
 
74
 
class CarTire(models.Model):
75
 
    """
76
 
    A single car tire. This to test that a user can only select their own cars.
77
 
    """
78
 
    car = models.ForeignKey(Car)
79
 
 
80
 
class Honeycomb(models.Model):
81
 
    location = models.CharField(max_length=20)
82
 
 
83
 
class Bee(models.Model):
84
 
    """
85
 
    A model with a FK to a model that won't be registered with the admin
86
 
    (Honeycomb) so the corresponding raw ID widget won't have a magnifying
87
 
    glass link to select related honeycomb instances.
88
 
    """
89
 
    honeycomb = models.ForeignKey(Honeycomb)
90
 
 
91
 
class Individual(models.Model):
92
 
    """
93
 
    A model with a FK to itself. It won't be registered with the admin, so the
94
 
    corresponding raw ID widget won't have a magnifying glass link to select
95
 
    related instances (rendering will be called programmatically in this case).
96
 
    """
97
 
    name = models.CharField(max_length=20)
98
 
    parent = models.ForeignKey('self', null=True)
99
 
 
100
 
class Company(models.Model):
101
 
    name = models.CharField(max_length=20)
102
 
 
103
 
class Advisor(models.Model):
104
 
    """
105
 
    A model with a m2m to a model that won't be registered with the admin
106
 
    (Company) so the corresponding raw ID widget won't have a magnifying
107
 
    glass link to select related company instances.
108
 
    """
109
 
    name = models.CharField(max_length=20)
110
 
    companies = models.ManyToManyField(Company)
111
 
 
112
 
 
113
 
@python_2_unicode_compatible
114
 
class Student(models.Model):
115
 
    name = models.CharField(max_length=255)
116
 
 
117
 
    def __str__(self):
118
 
        return self.name
119
 
 
120
 
    class Meta:
121
 
        ordering = ('name',)
122
 
 
123
 
@python_2_unicode_compatible
124
 
class School(models.Model):
125
 
    name = models.CharField(max_length=255)
126
 
    students = models.ManyToManyField(Student, related_name='current_schools')
127
 
    alumni = models.ManyToManyField(Student, related_name='previous_schools')
128
 
 
129
 
    def __str__(self):
130
 
        return self.name