Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib import admin
- from .models import Author
- from actions import export_as_excel
- # Register your models here.
- class AuthorAdmin(admin.ModelAdmin):
- list_display = ('id', 'first_name', 'last_name', 'age', 'link_own', 'news_counter', )
- list_filter = ('first_name', 'last_name', )
- search_fields = ('first_name', 'last_name', ) #si quiero buscar noticias por el apellido de su author 'author__last_name'
- list_editable = ('first_name', 'last_name', 'age', 'link_own' )
- actions = (export_as_excel,)
- def news_counter(self, obj):
- return obj.news.all().count() #Imprime en pantalla el numero de noticias del autor
- news_counter.short_description = 'Noticias'
- news_counter.allow_tags = True
- admin.site.register(Author, AuthorAdmin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement