Commit 8cf81673 authored by Ysabella Panghulan's avatar Ysabella Panghulan

added str method in Author and created Books class in models.py

parent 3fbebf10
from django.db import models from django.db import models
from django.core.exceptions import ValidationError
# Create your models here. # Create your models here.
class Author(models.Model): class Author(models.Model):
...@@ -7,3 +8,23 @@ class Author(models.Model): ...@@ -7,3 +8,23 @@ class Author(models.Model):
age = models.IntegerField(default = 0) age = models.IntegerField(default = 0)
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 self.first_name + " " + self.last_name
class Books(models.Model):
title = models.CharField(max_length = 100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length = 100)
year_published = models.DateTimeField('date published')
ISBN = models.CharField(max_length=13, validators=[validate_ISBN])
blurb = models.TextField(max_length = 200, min_length = 100)
def validate_ISBN(value):
if len(value) != 13:
raise ValidationError('Must be exactly 13 digits.')
if not value.isdigit():
raise ValidationError('Must only be digits.')
def __str__(self):
return self.title
\ 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