~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/modeltests/invalid_models/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
class FieldErrors(models.Model):
10
10
    charfield = models.CharField()
 
11
    charfield2 = models.CharField(max_length=-1)
 
12
    charfield3 = models.CharField(max_length="bad")
11
13
    decimalfield = models.DecimalField()
 
14
    decimalfield2 = models.DecimalField(max_digits=-1, decimal_places=-1)
 
15
    decimalfield3 = models.DecimalField(max_digits="bad", decimal_places="bad")
12
16
    filefield = models.FileField()
13
17
    choices = models.CharField(max_length=10, choices='bad')
14
18
    choices2 = models.CharField(max_length=10, choices=[(1,2,3),(1,2,3)])
76
80
    # M2M fields are symmetrical by default. Symmetrical M2M fields
77
81
    # on self don't require a related accessor, so many potential
78
82
    # clashes are avoided.
79
 
    validm2m_set = models.ManyToManyField("ValidM2M")
 
83
    validm2m_set = models.ManyToManyField("self")
80
84
 
81
 
    m2m_1 = models.ManyToManyField("ValidM2M", related_name='id')
82
 
    m2m_2 = models.ManyToManyField("ValidM2M", related_name='src_safe')
 
85
    m2m_1 = models.ManyToManyField("self", related_name='id')
 
86
    m2m_2 = models.ManyToManyField("self", related_name='src_safe')
83
87
 
84
88
    m2m_3 = models.ManyToManyField('self')
85
89
    m2m_4 = models.ManyToManyField('self')
90
94
 
91
95
    # Non-symmetrical M2M fields _do_ have related accessors, so
92
96
    # there is potential for clashes.
93
 
    selfclashm2m_set = models.ManyToManyField("SelfClashM2M", symmetrical=False)
 
97
    selfclashm2m_set = models.ManyToManyField("self", symmetrical=False)
94
98
 
95
 
    m2m_1 = models.ManyToManyField("SelfClashM2M", related_name='id', symmetrical=False)
96
 
    m2m_2 = models.ManyToManyField("SelfClashM2M", related_name='src_safe', symmetrical=False)
 
99
    m2m_1 = models.ManyToManyField("self", related_name='id', symmetrical=False)
 
100
    m2m_2 = models.ManyToManyField("self", related_name='src_safe', symmetrical=False)
97
101
 
98
102
    m2m_3 = models.ManyToManyField('self', symmetrical=False)
99
103
    m2m_4 = models.ManyToManyField('self', symmetrical=False)
180
184
 
181
185
class UniqueM2M(models.Model):
182
186
    """ Model to test for unique ManyToManyFields, which are invalid. """
183
 
    unique_people = models.ManyToManyField( Person, unique=True )
184
 
 
185
 
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute.
186
 
invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute.
187
 
invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute.
 
187
    unique_people = models.ManyToManyField(Person, unique=True)
 
188
 
 
189
class NonUniqueFKTarget1(models.Model):
 
190
    """ Model to test for non-unique FK target in yet-to-be-defined model: expect an error """
 
191
    tgt = models.ForeignKey('FKTarget', to_field='bad')
 
192
 
 
193
class UniqueFKTarget1(models.Model):
 
194
    """ Model to test for unique FK target in yet-to-be-defined model: expect no error """
 
195
    tgt = models.ForeignKey('FKTarget', to_field='good')
 
196
 
 
197
class FKTarget(models.Model):
 
198
    bad = models.IntegerField()
 
199
    good = models.IntegerField(unique=True)
 
200
 
 
201
class NonUniqueFKTarget2(models.Model):
 
202
    """ Model to test for non-unique FK target in previously seen model: expect an error """
 
203
    tgt = models.ForeignKey(FKTarget, to_field='bad')
 
204
 
 
205
class UniqueFKTarget2(models.Model):
 
206
    """ Model to test for unique FK target in previously seen model: expect no error """
 
207
    tgt = models.ForeignKey(FKTarget, to_field='good')
 
208
 
 
209
 
 
210
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
 
211
invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
 
212
invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer.
 
213
invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
 
214
invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute that is a positive integer.
 
215
invalid_models.fielderrors: "decimalfield2": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
 
216
invalid_models.fielderrors: "decimalfield2": DecimalFields require a "max_digits" attribute that is a positive integer.
 
217
invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
 
218
invalid_models.fielderrors: "decimalfield3": DecimalFields require a "max_digits" attribute that is a positive integer.
188
219
invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
189
220
invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).
190
221
invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples.
267
298
invalid_models.selfclashm2m: Reverse query name for m2m field 'm2m_4' clashes with field 'SelfClashM2M.selfclashm2m'. Add a related_name argument to the definition for 'm2m_4'.
268
299
invalid_models.missingrelations: 'rel1' has a relation with model Rel1, which has either not been installed or is abstract.
269
300
invalid_models.missingrelations: 'rel2' has an m2m relation with model Rel2, which has either not been installed or is abstract.
270
 
invalid_models.grouptwo: 'primary' has a manually-defined m2m relation through model Membership, which does not have foreign keys to Person and GroupTwo
271
 
invalid_models.grouptwo: 'secondary' has a manually-defined m2m relation through model MembershipMissingFK, which does not have foreign keys to Group and GroupTwo
 
301
invalid_models.grouptwo: 'primary' is a manually-defined m2m relation through model Membership, which does not have foreign keys to Person and GroupTwo
 
302
invalid_models.grouptwo: 'secondary' is a manually-defined m2m relation through model MembershipMissingFK, which does not have foreign keys to Group and GroupTwo
272
303
invalid_models.missingmanualm2mmodel: 'missing_m2m' specifies an m2m relation through model MissingM2MModel, which has not been installed
273
304
invalid_models.group: The model Group has two manually-defined m2m relations through the model Membership, which is not permitted. Please consider using an extra field on your intermediary model instead.
274
305
invalid_models.group: Intermediary model RelationshipDoubleFK has more than one foreign key to Person, which is ambiguous and is not permitted.
278
309
invalid_models.abstractrelationmodel: 'fk1' has a relation with model AbstractModel, which has either not been installed or is abstract.
279
310
invalid_models.abstractrelationmodel: 'fk2' has an m2m relation with model AbstractModel, which has either not been installed or is abstract.
280
311
invalid_models.uniquem2m: ManyToManyFields cannot be unique.  Remove the unique argument on 'unique_people'.
 
312
invalid_models.nonuniquefktarget1: Field 'bad' under model 'FKTarget' must have a unique=True constraint.
 
313
invalid_models.nonuniquefktarget2: Field 'bad' under model 'FKTarget' must have a unique=True constraint.
281
314
"""