lostplaces-backend/django_lostplaces/lostplaces/admin.py

38 lines
1.1 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
''' Classes and modules for the administrative backend. '''
2020-07-19 00:13:49 +02:00
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from django.utils import timezone
from lostplaces.models import *
2020-07-19 00:13:49 +02:00
# Register your models here.
class VoucherAdmin(admin.ModelAdmin):
fields = ['code', 'expires_when', 'created_when']
readonly_fields = ['created_when']
2020-09-18 21:03:05 +02:00
list_display = ('__str__', 'code', 'created_when', 'expires_when', 'valid')
def valid(self, instance):
return timezone.now() <= instance.expires_when
valid.boolean = True
class PhotoAlbumsAdmin(admin.ModelAdmin):
list_display = ('label', 'place', 'url' )
class PlacesAdmin(admin.ModelAdmin):
list_display = ('name', 'submitted_by', 'submitted_when')
class PlaceImagesAdmin(admin.ModelAdmin):
list_display = ('__str__', 'place', 'submitted_by')
admin.site.register(Explorer)
admin.site.register(Voucher, VoucherAdmin)
admin.site.register(Place, PlacesAdmin)
admin.site.register(PlaceImage, PlaceImagesAdmin)
admin.site.register(PhotoAlbum, PhotoAlbumsAdmin)