2009-12-20 03:46:58 +01:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-13 20:04:12 +02:00
|
|
|
|
2009-12-20 03:46:58 +01:00
|
|
|
class Author(models.Model):
|
|
|
|
first_name = models.CharField(max_length=255)
|
|
|
|
last_name = models.CharField(max_length=255)
|
|
|
|
dob = models.DateField()
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-01-21 14:13:44 +01:00
|
|
|
super().__init__(*args, **kwargs)
|
2009-12-20 03:46:58 +01:00
|
|
|
# Protect against annotations being passed to __init__ --
|
|
|
|
# this'll make the test suite get angry if annotations aren't
|
|
|
|
# treated differently than fields.
|
|
|
|
for k in kwargs:
|
|
|
|
assert k in [f.attname for f in self._meta.fields], \
|
2012-11-25 19:31:30 +01:00
|
|
|
"Author.__init__ got an unexpected parameter: %s" % k
|
2009-12-20 03:46:58 +01:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2009-12-20 03:46:58 +01:00
|
|
|
class Book(models.Model):
|
|
|
|
title = models.CharField(max_length=255)
|
2015-07-22 16:43:21 +02:00
|
|
|
author = models.ForeignKey(Author, models.CASCADE)
|
2013-08-11 22:19:09 +02:00
|
|
|
paperback = models.BooleanField(default=False)
|
2010-04-01 18:48:16 +02:00
|
|
|
opening_line = models.TextField()
|
2009-12-20 03:46:58 +01:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2015-07-22 20:54:42 +02:00
|
|
|
class BookFkAsPk(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
book = models.ForeignKey(Book, models.CASCADE, primary_key=True, db_column="not_the_default")
|
2015-07-22 20:54:42 +02:00
|
|
|
|
|
|
|
|
2009-12-20 03:46:58 +01:00
|
|
|
class Coffee(models.Model):
|
|
|
|
brand = models.CharField(max_length=255, db_column="name")
|
2016-02-16 16:03:37 +01:00
|
|
|
price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
|
2009-12-20 03:46:58 +01:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2017-05-18 19:11:23 +02:00
|
|
|
class MixedCaseIDColumn(models.Model):
|
|
|
|
id = models.AutoField(primary_key=True, db_column='MiXeD_CaSe_Id')
|
|
|
|
|
|
|
|
|
2009-12-20 03:46:58 +01:00
|
|
|
class Reviewer(models.Model):
|
2010-02-23 20:39:06 +01:00
|
|
|
reviewed = models.ManyToManyField(Book)
|
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2010-02-23 20:39:06 +01:00
|
|
|
class FriendlyAuthor(Author):
|
|
|
|
pass
|