2009-04-09 02:53:55 +08:00
|
|
|
import os
|
2008-10-08 18:09:44 +08:00
|
|
|
from django.db import models
|
2010-02-10 08:34:45 +08:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
2009-04-18 23:51:11 +08:00
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2008-10-08 18:09:44 +08:00
|
|
|
|
|
|
|
class Triple(models.Model):
|
|
|
|
left = models.IntegerField()
|
|
|
|
middle = models.IntegerField()
|
|
|
|
right = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
2009-04-11 15:41:59 +08:00
|
|
|
unique_together = (('left', 'middle'), (u'middle', u'right'))
|
2008-10-08 18:09:44 +08:00
|
|
|
|
2009-04-09 02:53:55 +08:00
|
|
|
class FilePathModel(models.Model):
|
|
|
|
path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
|
2009-05-02 15:03:33 +08:00
|
|
|
|
|
|
|
class Publication(models.Model):
|
|
|
|
title = models.CharField(max_length=30)
|
2009-05-07 22:48:04 +08:00
|
|
|
date_published = models.DateField()
|
2009-05-02 15:03:33 +08:00
|
|
|
|
|
|
|
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
|
2009-05-20 07:13:33 +08:00
|
|
|
|
|
|
|
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)
|
2010-02-10 08:34:45 +08:00
|
|
|
|
|
|
|
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.")
|
|
|
|
|