Added custom action to fix icons matching not only name but also class name with texture type

This commit is contained in:
Felipe Martín 2013-05-29 13:14:43 +02:00
parent b8a1aa33d5
commit ade7ec2284
1 changed files with 29 additions and 0 deletions

View File

@ -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(