Skip to content

Commit

Permalink
Add admin filter for callsign has owner
Browse files Browse the repository at this point in the history
  • Loading branch information
elnappo committed Apr 30, 2019
1 parent ad553d6 commit 35e7537
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion project_novis/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class UserAdmin(BaseUserAdmin):
'fields': ('email', 'password1', 'password2')}
),
)
ordering = ('email',)
ordering = ('-date_joined',)


@admin.register(UserValidation)
Expand Down
19 changes: 18 additions & 1 deletion project_novis/callsign/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ def set_call_sign_metadata(modeladmin, request, queryset):
set_call_sign_metadata.short_description = "Set default metadata"


class OwnerListFilter(admin.SimpleListFilter):
title = _("has owner")
parameter_name = "has_owner"

def lookups(self, request, model_admin):
return (("yes", _("Yes")),
("no", _("No")),)

def queryset(self, request, queryset):
if self.value() == "yes":
return queryset.filter(owner__isnull=False)

if self.value() == "no":
return queryset.filter(owner__isnull=True)


class PrefixListFilter(admin.SimpleListFilter):
title = _("has prefix")
parameter_name = "has_prefix"
Expand All @@ -67,7 +83,8 @@ def queryset(self, request, queryset):
class CallsignAdmin(BaseModelAdmin):
list_display = ("name", "country", "owner", "type")
list_display_links = ("name",)
list_filter = ("type", "_official_validated", PrefixListFilter, "country", "issued", "created", "modified")
list_filter = (OwnerListFilter, PrefixListFilter, "type", "_official_validated", "country", "issued",
"created", "modified")
search_fields = ("name",)
actions = [set_call_sign_metadata]

Expand Down

0 comments on commit 35e7537

Please sign in to comment.