Commit 81fadb25 authored by Julia Anishka's avatar Julia Anishka

added function to verify word count of blurb

parent 5f745c95
# Generated by Django 3.2 on 2023-03-27 10:08
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='books',
name='blurb',
field=models.TextField(max_length=200, validators=[django.core.validators.MinValueValidator(100)]),
),
]
......@@ -13,10 +13,17 @@ class Author(models.Model):
def __str__(self):
return self.first_name + ' ' + self.last_name
def verify_int(value):
def verify_ISBN(value):
if value.isdigit() == False:
raise ValidationError('ISBN must only be integers.')
def verify_wordCount(value):
word_count = len(value.split())
if word_count < 100:
raise ValidationError('Word count is less than 100. Required range is 100 to 200 words.')
if word_count > 200:
raise ValidationError('Word count is more than 200. Required range is 100 to 200 words.')
class Books(models.Model):
title = models.CharField(max_length = 70)
author = models.ForeignKey(Author, on_delete = models.CASCADE)
......@@ -24,8 +31,8 @@ class Books(models.Model):
year_published = models.IntegerField(null = True, blank = True,
validators=[MinValueValidator(1000), MaxValueValidator(datetime.now().year)]
)
ISBN = models.CharField(max_length = 13, validators = [MinValueValidator(13), verify_int])
blurb = models.TextField(max_length = 200, validators = [MinValueValidator(100)])
ISBN = models.CharField(max_length = 13, validators = [MinValueValidator(13), verify_ISBN])
blurb = models.TextField(validators = [verify_wordCount])
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