from django.db import models from datetime import date # Create your models here. class Book(models.Model): title=models.CharField(max_length=200) url=models.CharField(max_length=100) added=models.DateField(auto_now_add=True) @property def last_updated(self): chaps=Chapter.objects.filter(book=self).order_by('added') return chaps[0].added if chaps else None 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, blank=True, null=True) contents=models.TextField(blank=True, null=True) added=models.DateField(auto_now_add=True) def __str__(self): return self.title or self.book.title+' '+str(self.number)