2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2009-04-08 18:53:55 +00:00
|
|
|
import os
|
2011-10-13 21:34:56 +00:00
|
|
|
|
2010-02-10 00:34:45 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2011-10-13 21:34:56 +00:00
|
|
|
from django.db import models
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2012-12-08 10:13:52 +00:00
|
|
|
from django.utils._os import upath
|
2010-02-10 00:34:45 +00:00
|
|
|
|
2009-04-18 15:51:11 +00:00
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2008-10-08 10:09:44 +00:00
|
|
|
|
|
|
|
class Triple(models.Model):
|
|
|
|
left = models.IntegerField()
|
|
|
|
middle = models.IntegerField()
|
|
|
|
right = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
2012-06-07 16:08:47 +00:00
|
|
|
unique_together = (('left', 'middle'), ('middle', 'right'))
|
2008-10-08 10:09:44 +00:00
|
|
|
|
2009-04-08 18:53:55 +00:00
|
|
|
class FilePathModel(models.Model):
|
2012-12-08 10:13:52 +00:00
|
|
|
path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)
|
2009-05-02 07:03:33 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-05-02 07:03:33 +00:00
|
|
|
class Publication(models.Model):
|
|
|
|
title = models.CharField(max_length=30)
|
2009-05-07 14:48:04 +00:00
|
|
|
date_published = models.DateField()
|
2009-05-02 07:03:33 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-05-02 07:03:33 +00:00
|
|
|
return self.title
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-05-02 07:03:33 +00:00
|
|
|
class Article(models.Model):
|
|
|
|
headline = models.CharField(max_length=100)
|
|
|
|
publications = models.ManyToManyField(Publication)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-05-02 07:03:33 +00:00
|
|
|
return self.headline
|
2009-05-19 23:13:33 +00: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 00:34:45 +00: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.")
|
|
|
|
|
2010-02-23 20:02:18 +00:00
|
|
|
class Author(models.Model):
|
|
|
|
publication = models.OneToOneField(Publication, null=True, blank=True)
|
|
|
|
full_name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
class Author1(models.Model):
|
|
|
|
publication = models.OneToOneField(Publication, null=False)
|
|
|
|
full_name = models.CharField(max_length=255)
|
2010-08-05 03:59:20 +00:00
|
|
|
|
|
|
|
class Homepage(models.Model):
|
2012-03-31 13:55:03 +00:00
|
|
|
url = models.URLField()
|
2010-10-01 02:02:58 +00:00
|
|
|
|
|
|
|
class Document(models.Model):
|
|
|
|
myfile = models.FileField(upload_to='unused', blank=True)
|
2010-10-13 04:36:51 +00:00
|
|
|
|
|
|
|
class Edition(models.Model):
|
|
|
|
author = models.ForeignKey(Person)
|
|
|
|
publication = models.ForeignKey(Publication)
|
|
|
|
edition = models.IntegerField()
|
|
|
|
isbn = models.CharField(max_length=13, unique=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = (('author', 'publication'), ('publication', 'edition'),)
|