Added custom action to fix icons matching not only name but also class name with texture type
This commit is contained in:
parent
b8a1aa33d5
commit
ade7ec2284
|
@ -3,6 +3,27 @@ from django.contrib import admin
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.contenttypes import generic
|
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
|
# ATTRIBUTE
|
||||||
###
|
###
|
||||||
|
@ -206,6 +227,10 @@ class ItemAdmin(admin.ModelAdmin):
|
||||||
ModelAttributeAdminInline
|
ModelAttributeAdminInline
|
||||||
]
|
]
|
||||||
|
|
||||||
|
actions = [
|
||||||
|
fix_icons
|
||||||
|
]
|
||||||
|
|
||||||
def main_texture_html(self, obj):
|
def main_texture_html(self, obj):
|
||||||
if obj.main_texture:
|
if obj.main_texture:
|
||||||
return(
|
return(
|
||||||
|
@ -250,6 +275,10 @@ class BlockAdmin(admin.ModelAdmin):
|
||||||
ModelAttributeAdminInline
|
ModelAttributeAdminInline
|
||||||
]
|
]
|
||||||
|
|
||||||
|
actions = [
|
||||||
|
fix_icons
|
||||||
|
]
|
||||||
|
|
||||||
def main_texture_html(self, obj):
|
def main_texture_html(self, obj):
|
||||||
if obj.main_texture:
|
if obj.main_texture:
|
||||||
return(
|
return(
|
||||||
|
|
Loading…
Reference in New Issue