Commit 00e12e21 authored by Agu Syquia's avatar Agu Syquia

Updated models.py

Fixed the get_absolute_url function to work with the templates
parent cd9843e4
from django.db import models
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=60)
......@@ -11,6 +12,9 @@ class Author(models.Model):
name = str(self.first_name + " " + self.last_name)
return name
def get_absolute_url(self):
return reverse('bookshelf:author-details', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
......@@ -21,3 +25,6 @@ class Books(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk': self.pk})
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