blob: 145edad1bf78de56edff19a87c040f95f5f27c1d (
plain)
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
|
from __future__ import unicode_literals
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=255)
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100, help_text='Use both first and last names.',
unique=True)
class Meta:
ordering = ['name']
def __str__(self):
return self.name
@python_2_unicode_compatible
class Book(models.Model):
title = models.CharField(max_length=200)
pages = models.IntegerField(default=0)
author = models.ForeignKey(Author, null=True, blank=True)
pubdate = models.DateTimeField()
tags = models.ManyToManyField(Tag)
class Meta:
ordering = ['-pubdate', 'title']
unique_together = ['title', 'author']
def __str__(self):
return self.title
|