Commit 330e8693 authored by Elaiza Bolislis's avatar Elaiza Bolislis

Built models, such as Author and Books, for the bookshelf app

parent 0764fc92
This diff is collapsed.
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
import datetime
# Create your models here.
class Author(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
age = models.IntegerField()
nationality = models.CharField(max_length=255)
bio = models.TextField(max_length=700)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=150)
YEAR_PUBLISHED_CHOICES = [
(r, r)for r in range(1000, datetime.date.today().year+1)
]
year_published = models.PositiveIntegerField(
choices=YEAR_PUBLISHED_CHOICES,
default=datetime.date.today().year
)
ISBN = models.PositiveIntegerField(validators=[
MaxValueValidator(9999999999999),
MinValueValidator(1000000000000)],
default=1000000000000
)
blurb = models.TextField(max_length=1000)
def __str__(self):
return '{} ({}) by {}'.format(self.title, self.year_published, self.author)
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