PageRenderTime 62ms CodeModel.GetById 55ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/regressiontests/model_forms_regress/models.py

https://code.google.com/p/mango-py/
Python | 71 lines | 52 code | 19 blank | 0 comment | 2 complexity | 5b5b316faf9f68d79860ab60bc71cf76 MD5 | raw file
 1import os
 2from django.db import models
 3from django.core.exceptions import ValidationError
 4
 5
 6class Person(models.Model):
 7    name = models.CharField(max_length=100)
 8
 9class Triple(models.Model):
10    left = models.IntegerField()
11    middle = models.IntegerField()
12    right = models.IntegerField()
13
14    class Meta:
15        unique_together = (('left', 'middle'), (u'middle', u'right'))
16
17class FilePathModel(models.Model):
18    path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
19
20class Publication(models.Model):
21    title = models.CharField(max_length=30)
22    date_published = models.DateField()
23
24    def __unicode__(self):
25        return self.title
26
27class Article(models.Model):
28    headline = models.CharField(max_length=100)
29    publications = models.ManyToManyField(Publication)
30
31    def __unicode__(self):
32        return self.headline
33
34class CustomFileField(models.FileField):
35    def save_form_data(self, instance, data):
36        been_here = getattr(self, 'been_saved', False)
37        assert not been_here, "save_form_data called more than once"
38        setattr(self, 'been_saved', True)
39
40class CustomFF(models.Model):
41    f = CustomFileField(upload_to='unused', blank=True)
42
43class RealPerson(models.Model):
44    name = models.CharField(max_length=100)
45
46    def clean(self):
47        if self.name.lower() == 'anonymous':
48            raise ValidationError("Please specify a real name.")
49
50class Author(models.Model):
51    publication = models.OneToOneField(Publication, null=True, blank=True)
52    full_name = models.CharField(max_length=255)
53
54class Author1(models.Model):
55    publication = models.OneToOneField(Publication, null=False)
56    full_name = models.CharField(max_length=255)
57
58class Homepage(models.Model):
59    url = models.URLField(verify_exists=False)
60
61class Document(models.Model):
62    myfile = models.FileField(upload_to='unused', blank=True)
63
64class Edition(models.Model):
65    author = models.ForeignKey(Person)
66    publication = models.ForeignKey(Publication)
67    edition = models.IntegerField()
68    isbn = models.CharField(max_length=13, unique=True)
69
70    class Meta:
71        unique_together = (('author', 'publication'), ('publication', 'edition'),)