-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin.py
More file actions
31 lines (24 loc) · 1.05 KB
/
Copy pathadmin.py
File metadata and controls
31 lines (24 loc) · 1.05 KB
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
from django.contrib import admin
from django.utils.html import format_html
from logros.models import Achievement, UserAchievement
@admin.register(Achievement)
class AchievementAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', 'condition_type', 'is_active', 'sort_order')
list_filter = ('condition_type', 'is_active')
search_fields = ('name', 'slug')
prepopulated_fields = {'slug': ('name',)}
readonly_fields = ('image_preview',)
def image_preview(self, obj):
if obj.image:
return format_html(
'<img src="{}" style="max-height: 200px; border-radius: 8px;" />',
obj.image.url,
)
return '—'
image_preview.short_description = 'Vista previa'
@admin.register(UserAchievement)
class UserAchievementAdmin(admin.ModelAdmin):
list_display = ('user', 'achievement', 'unlocked_at', 'celebration_shown')
list_filter = ('achievement', 'celebration_shown')
search_fields = ('user__email', 'user__username', 'achievement__name')
raw_id_fields = ('user',)