1
from __future__ import unicode_literals
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
11
class Person(models.Model):
12
name = models.CharField(max_length=100)
14
class Triple(models.Model):
15
left = models.IntegerField()
16
middle = models.IntegerField()
17
right = models.IntegerField()
20
unique_together = (('left', 'middle'), ('middle', 'right'))
22
class FilePathModel(models.Model):
23
path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)
25
@python_2_unicode_compatible
26
class Publication(models.Model):
27
title = models.CharField(max_length=30)
28
date_published = models.DateField()
33
@python_2_unicode_compatible
34
class Article(models.Model):
35
headline = models.CharField(max_length=100)
36
publications = models.ManyToManyField(Publication)
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)
47
class CustomFF(models.Model):
48
f = CustomFileField(upload_to='unused', blank=True)
50
class RealPerson(models.Model):
51
name = models.CharField(max_length=100)
54
if self.name.lower() == 'anonymous':
55
raise ValidationError("Please specify a real name.")
57
class Author(models.Model):
58
publication = models.OneToOneField(Publication, null=True, blank=True)
59
full_name = models.CharField(max_length=255)
61
class Author1(models.Model):
62
publication = models.OneToOneField(Publication, null=False)
63
full_name = models.CharField(max_length=255)
65
class Homepage(models.Model):
66
url = models.URLField()
68
class Document(models.Model):
69
myfile = models.FileField(upload_to='unused', blank=True)
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)
78
unique_together = (('author', 'publication'), ('publication', 'edition'),)