summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/stuff/admin.py5
-rw-r--r--app/stuff/models.py32
2 files changed, 31 insertions, 6 deletions
diff --git a/app/stuff/admin.py b/app/stuff/admin.py
index dc15a1f..135b17b 100644
--- a/app/stuff/admin.py
+++ b/app/stuff/admin.py
@@ -24,6 +24,7 @@ class ItemAdmin(admin.ModelAdmin):
'purchase_price',
'image',
'item_type',
+ 'creator',
'serial_number',
'isbn',
),
@@ -36,7 +37,6 @@ class ItemAdmin(admin.ModelAdmin):
),
('Extra', {
'fields': (
- 'creator',
'creator_sort_last_name',
'creator_sort_first_name',
'current_price',
@@ -51,3 +51,6 @@ class ItemAdmin(admin.ModelAdmin):
)
}),
)
+
+ class Media:
+ js = ('image-loader.js', 'next-prev-links.js')
diff --git a/app/stuff/models.py b/app/stuff/models.py
index ee065a2..05a7f4f 100644
--- a/app/stuff/models.py
+++ b/app/stuff/models.py
@@ -1,5 +1,7 @@
from django.db import models
-from django.utils.encoding import force_text
+from django.urls import reverse
+from django.utils.html import format_html
+from django.utils import timezone
from django.conf import settings
@@ -25,8 +27,8 @@ class Item(models.Model):
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)
+ date_purchased = models.DateTimeField(blank=True, null=True, default=timezone.now)
+ date_added = models.DateTimeField(blank=True, null=True, default=timezone.now)
class Meta:
ordering = ['-date_added']
@@ -34,10 +36,30 @@ class Item(models.Model):
def __str__(self):
return self.title
+ @property
+ def get_previous_published(self):
+ return self.get_previous_by_date_added(status__exact=1)
+
+ @property
+ def get_next_published(self):
+ return self.get_next_by_date_added(status__exact=1)
+
+ @property
+ def get_previous_admin_url(self):
+ n = self.get_previous_by_date_added()
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[n.id])
+
+ @property
+ def get_next_admin_url(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ try:
+ return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=[self.get_next_by_date_added().pk])
+ except model.DoesNotExist:
+ return ''
+
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
+ return format_html('<img src="%s" width="100" style="width:100px">' % (self.get_image_url()))
admin_thumbnail.short_description = 'Thumbnail'