1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
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('<a href=""><img src="%s" width="100" style="width:100px"></a>' % (self.get_image_url()))
admin_thumbnail.allow_tags = True
admin_thumbnail.short_description = 'Thumbnail'
|