mirror of
https://github.com/nikdoof/vapemap.git
synced 2025-12-14 14:52:16 +00:00
Flesh out the Counties/Countries admin.
This commit is contained in:
@@ -3,6 +3,7 @@ from django.template import RequestContext
|
|||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.db.models import Count
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.contenttypes.generic import GenericStackedInline
|
from django.contrib.contenttypes.generic import GenericStackedInline
|
||||||
from .models import Chain, Store, Address, Brand, ClaimRequest, Link, LinkType, County, Country
|
from .models import Chain, Store, Address, Brand, ClaimRequest, Link, LinkType, County, Country
|
||||||
@@ -109,11 +110,39 @@ class ClaimAdmin(admin.ModelAdmin):
|
|||||||
approve_request.short_description = 'Approve selected requests.'
|
approve_request.short_description = 'Approve selected requests.'
|
||||||
|
|
||||||
|
|
||||||
|
class CountyAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ['name', 'address_count']
|
||||||
|
|
||||||
|
def address_count(self, obj):
|
||||||
|
return obj.address_count
|
||||||
|
address_count.admin_order_field = 'address_count'
|
||||||
|
|
||||||
|
def queryset(self, request):
|
||||||
|
qs = super(CountyAdmin, self).queryset(request)
|
||||||
|
return qs.annotate(address_count=Count('addresses'))
|
||||||
|
|
||||||
|
|
||||||
|
class CountryAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ['name', 'address_count', 'county_count']
|
||||||
|
|
||||||
|
def address_count(self, obj):
|
||||||
|
return obj.address_count
|
||||||
|
address_count.admin_order_field = 'address_count'
|
||||||
|
|
||||||
|
def county_count(self, obj):
|
||||||
|
return obj.county_count
|
||||||
|
county_count.admin_order_field = 'county_count'
|
||||||
|
|
||||||
|
def queryset(self, request):
|
||||||
|
qs = super(CountryAdmin, self).queryset(request)
|
||||||
|
return qs.annotate(address_count=Count('addresses'), county_count=Count('counties'))
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Chain, ChainAdmin)
|
admin.site.register(Chain, ChainAdmin)
|
||||||
admin.site.register(Store, StoreAdmin)
|
admin.site.register(Store, StoreAdmin)
|
||||||
admin.site.register(Address, admin.ModelAdmin)
|
admin.site.register(Address, admin.ModelAdmin)
|
||||||
admin.site.register(Brand, admin.ModelAdmin)
|
admin.site.register(Brand, admin.ModelAdmin)
|
||||||
admin.site.register(ClaimRequest, ClaimAdmin)
|
admin.site.register(ClaimRequest, ClaimAdmin)
|
||||||
admin.site.register(LinkType, admin.ModelAdmin)
|
admin.site.register(LinkType, admin.ModelAdmin)
|
||||||
admin.site.register(County, admin.ModelAdmin)
|
admin.site.register(County, CountyAdmin)
|
||||||
admin.site.register(Country, admin.ModelAdmin)
|
admin.site.register(Country, CountryAdmin)
|
||||||
@@ -120,6 +120,7 @@ class County(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
app_label = 'stores'
|
app_label = 'stores'
|
||||||
|
verbose_name_plural = 'Counties'
|
||||||
|
|
||||||
|
|
||||||
class Country(models.Model):
|
class Country(models.Model):
|
||||||
@@ -139,6 +140,7 @@ class Country(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
app_label = 'stores'
|
app_label = 'stores'
|
||||||
|
verbose_name_plural = 'Countries'
|
||||||
|
|
||||||
|
|
||||||
class Address(models.Model):
|
class Address(models.Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user