Skip to content

Commit

Permalink
Optionally use FKautocomplete if available
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoMaurizzi committed Jun 28, 2018
1 parent 9d594ba commit c3d1120
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions simple_locations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

from simple_locations.models import Point, AreaType, Area

try:
# optionally use django_extensions' ForeignKeyAutocompleteAdmin if available
from django_extensions.admin import ForeignKeyAutocompleteAdmin
class MPTTModelAutocompleteAdmin(MPTTModelAdmin, ForeignKeyAutocompleteAdmin):
pass
except ImportError:
class MPTTModelAutocompleteAdmin(MPTTModelAdmin):
pass


class PointAdmin(admin.ModelAdmin):
list_display = ('id', 'latitude', 'longitude')
Expand All @@ -18,11 +27,12 @@ class AreaTypeAdmin(admin.ModelAdmin):
list_display = ('slug', 'name')


class AreaAdmin(MPTTModelAdmin):
class AreaAdmin(MPTTModelAutocompleteAdmin):
list_display = ( 'name', 'kind', 'location', 'code')
search_fields = ['code', 'name']
list_filter = ('kind',)

related_search_fields = {'parent': ('^name',)}


admin.site.register(Point, PointAdmin)
admin.site.register(AreaType, AreaTypeAdmin)
Expand Down

0 comments on commit c3d1120

Please sign in to comment.