from django.db import models from datetime import date # Create your models here. class Book(models.Model): title=models.CharField(max_length=200) added=models.DateField(auto_now_add=True) @property def last_updated(self): return Chapter.objects.filter(book=self).order_by('added')[0].added def __str__(self): return self.title class Chapter(models.Model): book=models.ForeignKey(Book, on_delete=models.CASCADE) number=models.IntegerField(default=0) title=models.CharField(max_length=200) contents=models.TextField() added=models.DateField(auto_now_add=True) def __str__(self): return self.title or self.book.title+' '+self.number