mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2026-07-31 15:59:34 -04:00
- Implemented PDF generation for collections, allowing users to create printable itineraries. - Added support for Noto fonts to ensure proper rendering of text and emojis in PDFs. - Enhanced admin interfaces for achievements and adventures, improving usability and data management. - Introduced new fields and methods in models and serializers to support geolocation features and improve data handling. - Updated migrations to transition from latitude/longitude fields to a unified PointField for geographic data. - Added tests to validate PDF generation functionality and ensure reliability.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from django.contrib import admin
|
|
from allauth.account.decorators import secure_admin_login
|
|
|
|
from achievements.models import Achievement, UserAchievement
|
|
from main.admin_utils import admin_image_preview
|
|
|
|
admin.site.login = secure_admin_login(admin.site.login)
|
|
|
|
|
|
@admin.register(Achievement)
|
|
class AchievementAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'key', 'type', 'icon_preview', 'earned_count')
|
|
list_filter = ('type',)
|
|
search_fields = ('name', 'key', 'description')
|
|
readonly_fields = ('icon_preview_large',)
|
|
ordering = ('name',)
|
|
|
|
fieldsets = (
|
|
(None, {'fields': ('name', 'key', 'type', 'description')}),
|
|
('Rules', {'fields': ('condition',)}),
|
|
('Art', {'fields': ('icon', 'icon_preview_large')}),
|
|
)
|
|
|
|
@admin.display(description='Icon')
|
|
def icon_preview(self, obj):
|
|
return admin_image_preview(obj.icon, 32, 32)
|
|
|
|
@admin.display(description='Icon preview')
|
|
def icon_preview_large(self, obj):
|
|
return admin_image_preview(obj.icon, 96, 96)
|
|
|
|
@admin.display(description='Users earned')
|
|
def earned_count(self, obj):
|
|
return UserAchievement.objects.filter(achievement=obj).count()
|
|
|
|
|
|
@admin.register(UserAchievement)
|
|
class UserAchievementAdmin(admin.ModelAdmin):
|
|
list_display = ('user', 'achievement', 'earned_at')
|
|
list_filter = ('achievement', 'earned_at')
|
|
search_fields = ('user__username', 'achievement__name', 'achievement__key')
|
|
autocomplete_fields = ('user', 'achievement')
|
|
date_hierarchy = 'earned_at'
|
|
readonly_fields = ('earned_at',)
|