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

« back to all changes in this revision

Viewing changes to tests/model_forms_regress/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
import os
 
4
 
 
5
from django.core.exceptions import ValidationError
 
6
from django.db import models
 
7
from django.utils.encoding import python_2_unicode_compatible
 
8
from django.utils._os import upath
 
9
 
 
10
 
 
11
class Person(models.Model):
 
12
    name = models.CharField(max_length=100)
 
13
 
 
14
class Triple(models.Model):
 
15
    left = models.IntegerField()
 
16
    middle = models.IntegerField()
 
17
    right = models.IntegerField()
 
18
 
 
19
    class Meta:
 
20
        unique_together = (('left', 'middle'), ('middle', 'right'))
 
21
 
 
22
class FilePathModel(models.Model):
 
23
    path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)
 
24
 
 
25
@python_2_unicode_compatible
 
26
class Publication(models.Model):
 
27
    title = models.CharField(max_length=30)
 
28
    date_published = models.DateField()
 
29
 
 
30
    def __str__(self):
 
31
        return self.title
 
32
 
 
33
@python_2_unicode_compatible
 
34
class Article(models.Model):
 
35
    headline = models.CharField(max_length=100)
 
36
    publications = models.ManyToManyField(Publication)
 
37
 
 
38
    def __str__(self):
 
39
        return self.headline
 
40
 
 
41
class CustomFileField(models.FileField):
 
42
    def save_form_data(self, instance, data):
 
43
        been_here = getattr(self, 'been_saved', False)
 
44
        assert not been_here, "save_form_data called more than once"
 
45
        setattr(self, 'been_saved', True)
 
46
 
 
47
class CustomFF(models.Model):
 
48
    f = CustomFileField(upload_to='unused', blank=True)
 
49
 
 
50
class RealPerson(models.Model):
 
51
    name = models.CharField(max_length=100)
 
52
 
 
53
    def clean(self):
 
54
        if self.name.lower() == 'anonymous':
 
55
            raise ValidationError("Please specify a real name.")
 
56
 
 
57
class Author(models.Model):
 
58
    publication = models.OneToOneField(Publication, null=True, blank=True)
 
59
    full_name = models.CharField(max_length=255)
 
60
 
 
61
class Author1(models.Model):
 
62
    publication = models.OneToOneField(Publication, null=False)
 
63
    full_name = models.CharField(max_length=255)
 
64
 
 
65
class Homepage(models.Model):
 
66
    url = models.URLField()
 
67
 
 
68
class Document(models.Model):
 
69
    myfile = models.FileField(upload_to='unused', blank=True)
 
70
 
 
71
class Edition(models.Model):
 
72
    author = models.ForeignKey(Person)
 
73
    publication = models.ForeignKey(Publication)
 
74
    edition = models.IntegerField()
 
75
    isbn = models.CharField(max_length=13, unique=True)
 
76
 
 
77
    class Meta:
 
78
        unique_together = (('author', 'publication'), ('publication', 'edition'),)