from django.contrib import admin from . import models class ItemAdmin(admin.ModelAdmin): search_fields = ['title', 'description', 'url'] list_display = ['__str__', 'id', 'published'] list_filter = ( ("published", admin.EmptyFieldListFilter), ) raw_id_fields = ['user'] def get_changeform_initial_data(self, request): return {'user': request.user} admin.site.register(models.Item, ItemAdmin) class CommentAdmin(admin.ModelAdmin): search_fields = [ 'item__title', 'item__url', 'text', 'name', 'email' ] list_display = ['__str__', 'published'] list_filter = ( ("published", admin.EmptyFieldListFilter), ) raw_id_fields = ['item', 'user'] admin.site.register(models.Comment, CommentAdmin) class WeekAdmin(admin.ModelAdmin): search_fields = ['monday', 'title'] admin.site.register(models.Week, WeekAdmin)