Advertisement
SalahAdDinYusuf

Administrador Autores

Jul 26th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from django.contrib import admin
  2.  
  3. from .models import Author
  4. from actions import export_as_excel
  5. # Register your models here.
  6.  
  7. class AuthorAdmin(admin.ModelAdmin):
  8.     list_display = ('id', 'first_name', 'last_name', 'age', 'link_own', 'news_counter', )
  9.     list_filter = ('first_name', 'last_name', )
  10.     search_fields = ('first_name', 'last_name', ) #si quiero buscar noticias por el apellido de su author 'author__last_name'
  11.     list_editable = ('first_name', 'last_name', 'age', 'link_own' )
  12.     actions = (export_as_excel,)
  13.     def news_counter(self, obj):
  14.         return obj.news.all().count() #Imprime en pantalla el numero de noticias del autor
  15.     news_counter.short_description = 'Noticias'
  16.     news_counter.allow_tags = True
  17.  
  18. admin.site.register(Author, AuthorAdmin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement