Commit 7ecd500d authored by Alec Dayupay's avatar Alec Dayupay

Added get_absolute_url() in models

parent a1eb2c7b
from django.db import models
from django.urls import reverse
# Create your models here.
class Author(models.Model):
......@@ -11,6 +12,10 @@ class Author(models.Model):
def __str__(self):
return "{} {}".format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse("author_details", kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=50)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
......@@ -18,3 +23,6 @@ class Books(models.Model):
year_published = models.IntegerField(default=0)
ISBN = models.IntegerField(default=0)
blurb = models.TextField()
def get_absolute_url(self):
return reverse("book_details", kwargs={'pk': self.pk})
\ No newline at end of file
......@@ -7,6 +7,6 @@
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes">
<input type="Submit" value="Save Changes"/>
</form>
{% endblock %}
\ No newline at end of file
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