Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. from django.contrib import admin
  2.  
  3. # Register your models here.
  4. from django.db.models import Sum
  5. from django.utils.translation import ugettext_lazy as _
  6.  
  7. from managment.models import MonthPlan, MonthPlanElement, Cost
  8.  
  9.  
  10. class MonthPlanElementInline(admin.TabularInline):
  11. model = MonthPlanElement
  12. fields = ('category', 'value', 'get_costs')
  13. readonly_fields = ('get_costs', )
  14.  
  15. def get_costs(self, obj):
  16. return Cost.objects.filter(user=obj.plan.user,
  17. category=obj.category,
  18. datetime__month=obj.plan.month,
  19. datetime__year=obj.plan.year).aggregate(sum=Sum('value')).get('sum', 0)
  20. get_costs.short_description = _('Траты')
  21.  
  22.  
  23. @admin.register(MonthPlan)
  24. class MonthPlanAdmin(admin.ModelAdmin):
  25. inlines = (MonthPlanElementInline, )
  26. exclude = []
  27. list_display = ('user', 'month', 'year')
  28. list_filter = ('month', 'year')
  29. search_fields = ('user__username',)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement