Commit fb552120 authored by Ysabella Panghulan's avatar Ysabella Panghulan

added get_books and get_absolute_url methods in Author class

parent 558526b8
...@@ -14,6 +14,12 @@ class Author(models.Model): ...@@ -14,6 +14,12 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return self.first_name + " " + self.last_name return self.first_name + " " + self.last_name
def get_absolute_url(self):
return reverse('author-details', kwargs={'pk': self.pk})
def books(self):
return Books.objects.filter(author=self)
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length = 100) title = models.CharField(max_length = 100)
author = models.ForeignKey(Author, on_delete = models.CASCADE) author = models.ForeignKey(Author, on_delete = models.CASCADE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment