''' fieldsets = [ (None, {'fields': ['id','name','venue','start_datetime','published','heading','photos','content']}), ('Tracking', {'fields':['last_updated_date','creation_date'], 'classes': ['collapse']}), ] list_display = ('id','name','venue','start_datetime','published') search_fields = ['name','heading',] list_filter = ['venue','start_datetime','creation_date'] readonly_fields = ('last_updated_date','creation_date','id') raw_id_fields = ('venue','photos',) admin_site.register(CalendarEvent, CalendarEventAdmin) class VenueAdmin(admin.ModelAdmin): ''' Venue admin customisation ''' fieldsets = [ (None, {'fields': ['id','name']}), ('Location', {'fields':['address1','address2','town_or_city','postcode','maps_embed']}), ('Contact', {'fields':['website','email','telephone_number']}), ('Tracking', {'fields':['last_updated_date','creation_date'], 'classes': ['collapse']}), ] list_display = ('id','name', 'town_or_city','postcode') search_fields = ['name',]
from django.contrib import admin from articles.models.photo import Photo from articles.admin.admin_site import admin_site class PhotoAdmin(admin.ModelAdmin): ''' Photo admin customisation ''' fieldsets = [ (None, {'fields': ['id','title','caption','image','photographer']}), ('Tracking', {'fields':['last_updated_date','creation_date'], 'classes': ['collapse']}), ] list_display = ('id','title','caption', 'last_updated_date','creation_date','photographer') search_fields = ['title','caption','photographer'] list_filter = ['photographer','creation_date','last_updated_date'] readonly_fields = ('last_updated_date','creation_date','id') #Registering models admin_site.register(Photo,PhotoAdmin)
from django.contrib import admin from articles.models.category import Category from articles.admin.admin_site import admin_site class CategoryAdmin(admin.ModelAdmin): ''' Category admin customisation ''' fieldsets = [ (None, {'fields': ['id','name','sequence','parent']}), ('Tracking', {'fields':['last_updated_date','creation_date'], 'classes': ['collapse']}), ] list_display = ('id','name','path_and_name', 'last_updated_date','creation_date',) search_fields = ['name',] readonly_fields = ('last_updated_date','creation_date','id',) #Registering models admin_site.register(Category,CategoryAdmin)
class ArticleAdmin(admin.ModelAdmin): ''' Article admin customisation ''' fieldsets = [ (None, {'fields': ['id','name','category','search_words','published','front_page','header','tagline','thumbnail','photos','youtube_embed','content','author']}), ('Tracking', {'fields':['last_updated_date','creation_date'], 'classes': ['collapse']}), ] list_display = ('id','name','category', 'last_updated_date','creation_date','published','front_page') search_fields = ['search_words','name','header','tagline',] list_filter = ['category','front_page','creation_date','last_updated_date'] readonly_fields = ('last_updated_date','creation_date','id') raw_id_fields = ('photos',) formfield_overrides = { models.CharField: {'widget': TextInput(attrs={'size':'100'})}, models.TextField: {'widget': Textarea(attrs={'rows':50, 'cols':100})}, } #Auto populates author field with current user def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == 'author': kwargs['initial'] = request.user.id return super(ArticleAdmin, self).formfield_for_foreignkey( db_field, request, **kwargs ) admin_site.register(Article, ArticleAdmin)