~ubuntu-branches/ubuntu/utopic/python-django/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Luke Faraone, Jakub Wilk, Luke Faraone
  • Date: 2013-05-09 15:10:47 UTC
  • mfrom: (1.1.21) (4.4.27 sid)
  • Revision ID: package-import@ubuntu.com-20130509151047-aqv8d71oj9wvcv8c
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Luke Faraone ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import unicode_literals
 
2
 
1
3
import datetime
2
4
 
3
5
from django.db import models
 
6
from django.utils.encoding import python_2_unicode_compatible
4
7
 
 
8
@python_2_unicode_compatible
5
9
class Place(models.Model):
6
10
    name = models.CharField(max_length=50)
7
11
    address = models.CharField(max_length=80)
9
13
    class Meta:
10
14
        ordering = ('name',)
11
15
 
12
 
    def __unicode__(self):
13
 
        return u"%s the place" % self.name
 
16
    def __str__(self):
 
17
        return "%s the place" % self.name
14
18
 
 
19
@python_2_unicode_compatible
15
20
class Restaurant(Place):
16
21
    serves_hot_dogs = models.BooleanField()
17
22
    serves_pizza = models.BooleanField()
18
23
 
19
 
    def __unicode__(self):
20
 
        return u"%s the restaurant" % self.name
 
24
    def __str__(self):
 
25
        return "%s the restaurant" % self.name
21
26
 
 
27
@python_2_unicode_compatible
22
28
class ItalianRestaurant(Restaurant):
23
29
    serves_gnocchi = models.BooleanField()
24
30
 
25
 
    def __unicode__(self):
26
 
        return u"%s the italian restaurant" % self.name
 
31
    def __str__(self):
 
32
        return "%s the italian restaurant" % self.name
27
33
 
 
34
@python_2_unicode_compatible
28
35
class ParkingLot(Place):
29
36
    # An explicit link to the parent (we can control the attribute name).
30
37
    parent = models.OneToOneField(Place, primary_key=True, parent_link=True)
31
38
    capacity = models.IntegerField()
32
39
 
33
 
    def __unicode__(self):
34
 
        return u"%s the parking lot" % self.name
 
40
    def __str__(self):
 
41
        return "%s the parking lot" % self.name
35
42
 
36
43
class ParkingLot2(Place):
37
44
    # In lieu of any other connector, an existing OneToOneField will be
62
69
class SelfRefChild(SelfRefParent):
63
70
    child_data = models.IntegerField()
64
71
 
 
72
@python_2_unicode_compatible
65
73
class Article(models.Model):
66
74
    headline = models.CharField(max_length=100)
67
75
    pub_date = models.DateTimeField()
68
76
    class Meta:
69
77
        ordering = ('-pub_date', 'headline')
70
78
 
71
 
    def __unicode__(self):
 
79
    def __str__(self):
72
80
        return self.headline
73
81
 
74
82
class ArticleWithAuthor(Article):
89
97
class QualityControl(Evaluation):
90
98
    assignee = models.CharField(max_length=50)
91
99
 
 
100
@python_2_unicode_compatible
92
101
class BaseM(models.Model):
93
102
    base_name = models.CharField(max_length=100)
94
103
 
95
 
    def __unicode__(self):
 
104
    def __str__(self):
96
105
        return self.base_name
97
106
 
 
107
@python_2_unicode_compatible
98
108
class DerivedM(BaseM):
99
109
    customPK = models.IntegerField(primary_key=True)
100
110
    derived_name = models.CharField(max_length=100)
101
111
 
102
 
    def __unicode__(self):
 
112
    def __str__(self):
103
113
        return "PK = %d, base_name = %s, derived_name = %s" \
104
114
                % (self.customPK, self.base_name, self.derived_name)
105
115
 
108
118
 
109
119
    class Meta:
110
120
        abstract = True
111
 
        verbose_name_plural = u'Audits'
 
121
        verbose_name_plural = 'Audits'
112
122
 
113
123
class CertificationAudit(AuditBase):
114
124
    class Meta(AuditBase.Meta):
118
128
    auditing_dept = models.CharField(max_length=20)
119
129
 
120
130
# Check that abstract classes don't get m2m tables autocreated.
 
131
@python_2_unicode_compatible
121
132
class Person(models.Model):
122
133
    name = models.CharField(max_length=100)
123
134
 
124
135
    class Meta:
125
136
        ordering = ('name',)
126
137
 
127
 
    def __unicode__(self):
 
138
    def __str__(self):
128
139
        return self.name
129
140
 
 
141
@python_2_unicode_compatible
130
142
class AbstractEvent(models.Model):
131
143
    name = models.CharField(max_length=100)
132
144
    attendees = models.ManyToManyField(Person, related_name="%(class)s_set")
135
147
        abstract = True
136
148
        ordering = ('name',)
137
149
 
138
 
    def __unicode__(self):
 
150
    def __str__(self):
139
151
        return self.name
140
152
 
141
153
class BirthdayParty(AbstractEvent):
163
175
 
164
176
class TrainStation(Station):
165
177
    zone = models.IntegerField()
 
178
 
 
179
class User(models.Model):
 
180
    username = models.CharField(max_length=30, unique=True)
 
181
 
 
182
class Profile(User):
 
183
    profile_id = models.AutoField(primary_key=True)
 
184
    extra = models.CharField(max_length=30, blank=True)