diff --git a/Karoo_BackEnd/Karoo_BackEnd/account_module/admin.py b/Karoo_BackEnd/Karoo_BackEnd/account_module/admin.py index 5ae8d20..4857cba 100644 --- a/Karoo_BackEnd/Karoo_BackEnd/account_module/admin.py +++ b/Karoo_BackEnd/Karoo_BackEnd/account_module/admin.py @@ -1,9 +1,8 @@ from django.contrib import admin -from .models import User, DiscountCode, Address -# Register your models here. +from .models import User, DiscountCode, Address, City, Province -class AdminUser(admin.ModelAdmin): +class AdminUser(admin.ModelAdmin): list_display = [ 'email', 'full_name','is_active', 'phone_number'] list_filter = ['is_staff','is_active' ] @@ -13,11 +12,33 @@ class AdminDiscountCode(admin.ModelAdmin): list_filter = ['discount_percent'] -class AdminAddress(admin.ModelAdmin): - list_display = ['user','province','city'] - list_filter = ['city'] +class CityInline(admin.TabularInline): + model = City + extra = 1 + + +class ProvinceAdmin(admin.ModelAdmin): + list_display = ('name',) + search_fields = ('name',) + ordering = ('name',) + inlines = [CityInline] + + +class CityAdmin(admin.ModelAdmin): + list_display = ('name', 'province') + search_fields = ('name', 'province__name') + list_filter = ('province',) + ordering = ('name',) + +class AddressAdmin(admin.ModelAdmin): + list_display = ('user', 'province', 'city') + search_fields = ('user__username', 'province__name', 'city__name') + list_filter = ('province', 'city') + ordering = ('user',) admin.site.register(User, AdminUser) -admin.site.register(DiscountCode, AdminDiscountCode) -admin.site.register(Address, AdminAddress) \ No newline at end of file +#admin.site.register(DiscountCode, AdminDiscountCode) +admin.site.register(Address, AddressAdmin) +admin.site.register(Province, ProvinceAdmin) +admin.site.register(City, CityAdmin) \ No newline at end of file