From ade7ec2284600474e01a753a7ce0afd681156f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Wed, 29 May 2013 13:14:43 +0200 Subject: [PATCH] Added custom action to fix icons matching not only name but also class name with texture type --- minecraftcodex/database/models.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/minecraftcodex/database/models.py b/minecraftcodex/database/models.py index b0aaaaa..abae369 100644 --- a/minecraftcodex/database/models.py +++ b/minecraftcodex/database/models.py @@ -3,6 +3,27 @@ from django.contrib import admin from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic + +### +# Custom actions +### +def fix_icons(modeladmin, request, queryset): + items = queryset + for item in items: + try: + class_name = "%ss" % item.__class__.__name__.lower() + icon = Texture.objects.get( + name__exact=item.internal_name, + type=class_name + ) + item.main_texture = icon + item.save() + except: + item.main_texture = None + item.save() +fix_icons.short_description = "Fix icons for the selected items" + + ### # ATTRIBUTE ### @@ -206,6 +227,10 @@ class ItemAdmin(admin.ModelAdmin): ModelAttributeAdminInline ] + actions = [ + fix_icons + ] + def main_texture_html(self, obj): if obj.main_texture: return( @@ -250,6 +275,10 @@ class BlockAdmin(admin.ModelAdmin): ModelAttributeAdminInline ] + actions = [ + fix_icons + ] + def main_texture_html(self, obj): if obj.main_texture: return(