2021-10-24 23:59:35 +11:00
|
|
|
from django.db import models
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
class Book(models.Model):
|
|
|
|
title=models.CharField(max_length=200)
|
2021-10-27 19:09:18 +11:00
|
|
|
url=models.CharField(max_length=100)
|
2021-10-24 23:59:35 +11:00
|
|
|
added=models.DateField(auto_now_add=True)
|
2021-10-27 19:09:18 +11:00
|
|
|
|
2021-10-24 23:59:35 +11:00
|
|
|
@property
|
|
|
|
def last_updated(self):
|
2021-10-29 05:05:42 +11:00
|
|
|
chaps=Chapter.objects.filter(book=self).order_by('added')
|
|
|
|
return chaps[0].added if chaps else None
|
2021-10-24 23:59:35 +11:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Chapter(models.Model):
|
|
|
|
book=models.ForeignKey(Book, on_delete=models.CASCADE)
|
|
|
|
number=models.IntegerField(default=0)
|
2021-10-27 19:09:18 +11:00
|
|
|
title=models.CharField(max_length=200, blank=True, null=True)
|
|
|
|
contents=models.TextField(blank=True, null=True)
|
2021-10-24 23:59:35 +11:00
|
|
|
added=models.DateField(auto_now_add=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
2021-10-27 19:09:18 +11:00
|
|
|
return self.title or self.book.title+' '+str(self.number)
|