Added a __str__ method to return the key of the model object when called in admin for ease of use

parent e06bee52
...@@ -7,6 +7,9 @@ class Author(models.Model): ...@@ -7,6 +7,9 @@ class Author(models.Model):
nationality = models.CharField(max_length=50) nationality = models.CharField(max_length=50)
bio = models.TextField(max_length=700) bio = models.TextField(max_length=700)
def __str__(self):
return '{}, {}'.format(self.first_name, self.last_name)
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=180) title = models.CharField(max_length=180)
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE)
...@@ -14,3 +17,6 @@ class Book(models.Model): ...@@ -14,3 +17,6 @@ class Book(models.Model):
year_published = models.CharField(max_length=4) year_published = models.CharField(max_length=4)
ISBN = models.CharField(max_length=13) ISBN = models.CharField(max_length=13)
blurb = models.TextField(max_length=200) blurb = models.TextField(max_length=200)
def __str__(self):
return self.title
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