Commit a14b4d1f authored by Julia Anishka's avatar Julia Anishka

created new function to verify ISBN in models.py

parent bb88e691
...@@ -13,9 +13,11 @@ class Author(models.Model): ...@@ -13,9 +13,11 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return self.first_name + ' ' + self.last_name return self.first_name + ' ' + self.last_name
def verify_int(value): def verify_ISBN(value):
if value.isdigit() == False: if value.isdigit() == False:
raise ValidationError('ISBN must only be integers.') raise ValidationError('ISBN must only be integers.')
if value != 13:
raise ValidationError('ISBN must be a 13 digit number.')
def verify_wordCount(value): def verify_wordCount(value):
word_count = int(len(value.split())) word_count = int(len(value.split()))
...@@ -31,7 +33,7 @@ class Books(models.Model): ...@@ -31,7 +33,7 @@ class Books(models.Model):
year_published = models.IntegerField(null = True, blank = True, year_published = models.IntegerField(null = True, blank = True,
validators=[MinValueValidator(1000), MaxValueValidator(datetime.now().year)] validators=[MinValueValidator(1000), MaxValueValidator(datetime.now().year)]
) )
ISBN = models.CharField(max_length = 13, validators = [MinValueValidator(13), verify_int]) ISBN = models.CharField(validators = [verify_ISBN])
blurb = models.TextField(validators = [verify_wordCount]) blurb = models.TextField(validators = [verify_wordCount])
def __str__(self): def __str__(self):
......
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