Lagt til støtte for å vise kategorier med 'show'-kommandoen.
This commit is contained in:
python
@ -12,6 +12,24 @@ class Category(models.Model):
|
||||
id = models.CharField(max_length=255, primary_key=True)
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
def to_string(self):
|
||||
str = 'category %s\nName: %s\n' % (self.id, self.name)
|
||||
str += 'Placement: %s\n' % self.placements_str()
|
||||
str += 'Books:\n'
|
||||
for book in self.books.all():
|
||||
str += ' %-13s %-10s %s\n' % (book.isbn, book.getid() or '', book.title)
|
||||
if len(self.books.all()) == 0:
|
||||
str += ' (no books in this category)\n'
|
||||
return str
|
||||
|
||||
def to_dict(self):
|
||||
return { 'action': 'edit-category',
|
||||
'id': self.id, 'name': self.name,
|
||||
'placement': self.placements_str() }
|
||||
|
||||
def placements_str(self):
|
||||
return ', '.join(map(lambda pl: pl.shelf, self.placement.all()))
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
@ -33,7 +51,7 @@ class Book(models.Model):
|
||||
# id = models.CharField(max_length=255)
|
||||
title = models.CharField(max_length=511)
|
||||
subtitle = models.CharField(max_length=511, null=True, blank=True)
|
||||
category = models.ForeignKey(Category, null=True, blank=True)
|
||||
category = models.ForeignKey(Category, null=True, blank=True, related_name='books')
|
||||
publisher = models.CharField(max_length=255, null=True, blank=True)
|
||||
published_year = models.IntegerField(null=True, blank=True)
|
||||
edition = models.IntegerField(null=True, blank=True)
|
||||
|
Reference in New Issue
Block a user