from django.db import models from django.utils.encoding import force_text from django.conf import settings class Item(models.Model): isbn = models.CharField(max_length=100, blank=True, null=True) serial_number = models.CharField(max_length=100, blank=True, null=True) ITEM_TYPES = ( (0, 'Book'), (1, 'Apparel'), (2, 'Gadget'), (3, 'Furniture'), ) item_type = models.IntegerField(choices=ITEM_TYPES, default=0) title = models.CharField(max_length=200) creator = models.CharField(max_length=200, blank=True, null=True) creator_sort_last_name = models.CharField(max_length=200, blank=True, null=True) creator_sort_first_name = models.CharField(max_length=200, blank=True, null=True) current_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) retail_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) purchase_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) amazon_url = models.CharField(max_length=400, blank=True, null=True) image_url = models.CharField(max_length=400, blank=True, null=True) image = models.FileField(upload_to='stuff/', null=True, blank=True) item_format = models.CharField(max_length=255, blank=True, null=True) date_released = models.DateTimeField(blank=True, null=True) date_purchased = models.DateTimeField(blank=True, null=True) date_added = models.DateTimeField(blank=True, null=True) class Meta: ordering = ['-date_added'] def __str__(self): return self.title def get_image_url(self): return '%s%s' % (settings.MEDIA_URL, self.image) def admin_thumbnail(self): return force_text('' % (self.get_image_url())) admin_thumbnail.allow_tags = True admin_thumbnail.short_description = 'Thumbnail'