Skip to content

Commit

Permalink
Merge pull request #2 from earthpyy/admin-site
Browse files Browse the repository at this point in the history
Admin site
  • Loading branch information
earthpyy authored Dec 9, 2023
2 parents be0a442 + caa43e0 commit 6fdfaba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions thailand_geography/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.contrib import admin

from .models import Province, District, Subdistrict


class ProvinceAdmin(admin.ModelAdmin):
list_display = ('id', 'name_en', 'name_th')
search_fields = ('name_en', 'name_th')


class DistrictAdmin(admin.ModelAdmin):
list_display = ('id', 'province', 'name_en', 'name_th')
search_fields = ('name_en', 'name_th', 'province__name_en', 'province__name_th')
list_select_related = ('province',)


class SubdistrictAdmin(admin.ModelAdmin):
list_display = ('id', 'province', 'district', 'name_en', 'name_th')
search_fields = (
'name_en', 'name_th', 'province__name_en', 'province__name_th', 'district__name_en', 'district__name_th',
)
list_select_related = ('district__province',)

def province(self, obj):
return obj.get_province()


admin.site.register(Province, ProvinceAdmin)
admin.site.register(District, DistrictAdmin)
admin.site.register(Subdistrict, SubdistrictAdmin)
9 changes: 9 additions & 0 deletions thailand_geography/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Province(models.Model):
class Meta:
ordering = ('id',)

def __str__(self):
return str(self.name_th)


class District(models.Model):
id = models.PositiveIntegerField(primary_key=True)
Expand All @@ -19,6 +22,9 @@ class District(models.Model):
class Meta:
ordering = ('id',)

def __str__(self):
return f'{self.province.name_th} / {self.name_th}'


class Subdistrict(models.Model):
id = models.PositiveIntegerField(primary_key=True)
Expand All @@ -31,3 +37,6 @@ class Meta:

def get_province(self):
return self.district.province

def __str__(self):
return f'{self.get_province().name_th} / {self.district.name_th} / {self.name_th}'

0 comments on commit 6fdfaba

Please sign in to comment.