Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib import admin
- # Register your models here.
- from django.db.models import Sum
- from django.utils.translation import ugettext_lazy as _
- from managment.models import MonthPlan, MonthPlanElement, Cost
- class MonthPlanElementInline(admin.TabularInline):
- model = MonthPlanElement
- fields = ('category', 'value', 'get_costs')
- readonly_fields = ('get_costs', )
- def get_costs(self, obj):
- return Cost.objects.filter(user=obj.plan.user,
- category=obj.category,
- datetime__month=obj.plan.month,
- datetime__year=obj.plan.year).aggregate(sum=Sum('value')).get('sum', 0)
- get_costs.short_description = _('Траты')
- @admin.register(MonthPlan)
- class MonthPlanAdmin(admin.ModelAdmin):
- inlines = (MonthPlanElementInline, )
- exclude = []
- list_display = ('user', 'month', 'year')
- list_filter = ('month', 'year')
- search_fields = ('user__username',)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement