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):
...@@ -10,6 +11,10 @@ class Author(models.Model): ...@@ -10,6 +11,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)
...@@ -17,4 +22,7 @@ class Books(models.Model): ...@@ -17,4 +22,7 @@ class Books(models.Model):
publisher = models.CharField(max_length=50) publisher = models.CharField(max_length=50)
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()
\ No newline at end of file
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