-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
/
models.py
49 lines (35 loc) · 1.39 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from django.db import models
from django.core.exceptions import ValidationError
class Person(models.Model):
name = models.CharField(max_length=100)
class Triple(models.Model):
left = models.IntegerField()
middle = models.IntegerField()
right = models.IntegerField()
class Meta:
unique_together = (('left', 'middle'), (u'middle', u'right'))
class FilePathModel(models.Model):
path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
class Publication(models.Model):
title = models.CharField(max_length=30)
date_published = models.DateField()
def __unicode__(self):
return self.title
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
def __unicode__(self):
return self.headline
class CustomFileField(models.FileField):
def save_form_data(self, instance, data):
been_here = getattr(self, 'been_saved', False)
assert not been_here, "save_form_data called more than once"
setattr(self, 'been_saved', True)
class CustomFF(models.Model):
f = CustomFileField(upload_to='unused', blank=True)
class RealPerson(models.Model):
name = models.CharField(max_length=100)
def clean(self):
if self.name.lower() == 'anonymous':
raise ValidationError("Please specify a real name.")