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