django-orchestra/orchestra/contrib/plans/admin.py

38 lines
1.2 KiB
Python
Raw Normal View History

2014-11-18 13:59:21 +00:00
from django.contrib import admin
from orchestra.admin import ExtendedModelAdmin
from orchestra.admin.utils import insertattr
2015-04-05 10:46:24 +00:00
from orchestra.contrib.accounts.admin import AccountAdminMixin
from orchestra.contrib.services.models import Service
2014-11-18 13:59:21 +00:00
from .models import Plan, ContractedPlan, Rate
class RateInline(admin.TabularInline):
model = Rate
2015-04-21 13:12:48 +00:00
ordering = ('service', 'plan', 'quantity')
2014-11-18 13:59:21 +00:00
class PlanAdmin(ExtendedModelAdmin):
2015-04-09 14:32:10 +00:00
list_display = ('name', 'is_default', 'is_combinable', 'allow_multiple', 'is_active')
list_filter = ('is_default', 'is_combinable', 'allow_multiple', 'is_active')
2014-11-18 13:59:21 +00:00
fields = ('verbose_name', 'name', 'is_default', 'is_combinable', 'allow_multiple')
prepopulated_fields = {
'name': ('verbose_name',)
}
change_readonly_fields = ('name',)
inlines = [RateInline]
class ContractedPlanAdmin(AccountAdminMixin, admin.ModelAdmin):
list_display = ('plan', 'account_link')
list_filter = ('plan__name',)
2015-04-16 13:15:21 +00:00
list_select_related = ('plan', 'account')
search_fields = ('account__username', 'plan__name', 'id')
2014-11-18 13:59:21 +00:00
2015-05-09 15:37:35 +00:00
2014-11-18 13:59:21 +00:00
admin.site.register(Plan, PlanAdmin)
admin.site.register(ContractedPlan, ContractedPlanAdmin)
insertattr(Service, 'inlines', RateInline)