Commit feae9c03 authored by Daniel W Bond's avatar Daniel W Bond

added title and author fields to lookout, which are autopopulated on save by calling ISBNMetadata

parent 51f28c46
......@@ -7,6 +7,7 @@ from model_utils.models import TimeStampedModel
from randomslugfield import RandomSlugField
# imports from your apps
from trades.models import Listing
from trades.utils import ISBNMetadata
from core.models import Student
......@@ -17,6 +18,14 @@ class Lookout(TimeStampedModel):
max_length=20,
validators=[RegexValidator('[0-9xX-]{10,20}',
message='Please enter a valid ISBN.')])
title = models.CharField(max_length=200,
null=True, blank=True)
author = models.CharField(max_length=200,
null=True, blank=True)
# would have to load in every conceivable course first
# course = models.ForeignKey(Course)
slug = RandomSlugField(length=6)
......@@ -25,9 +34,21 @@ class Lookout(TimeStampedModel):
isbn_listings = models.Q(isbn=self.isbn, exchanged=False, cancelled=False)
return Listing.objects.filter(isbn_listings)
def get_title_or_isbn(self):
if self.title:
return self.title
else:
return self.isbn
def get_absolute_url(self):
return reverse('detail_lookout', kwargs={'slug': self.slug})
def save(self, *args, **kwargs):
isbn_metadata = ISBNMetadata(self.isbn)
self.title = isbn_metadata.get('title')
self.author = isbn_metadata.get('authors')
super().save(*args, **kwargs)
def __unicode__(self):
return '%s %s' % (self.owner.user.username, self.isbn)
......
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