Skip to content

Commit

Permalink
Always include the username in search_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Oct 11, 2018
1 parent d3017eb commit c93ad94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Change log
`Next version`_
~~~~~~~~~~~~~~~

- Ensured that the username is part of ``search_fields`` for all models
registered with the admin interface.


`0.3`_ (2018-09-21)
~~~~~~~~~~~~~~~~~~~

Expand Down
9 changes: 7 additions & 2 deletions user_payments/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.contrib.auth import get_user_model

from . import models

Expand All @@ -23,12 +24,16 @@ class PaymentAdmin(admin.ModelAdmin):
)
list_filter = ("charged_at", "payment_service_provider")
raw_id_fields = ("user",)
search_fields = ("email", "transaction")
search_fields = (
"email",
"transaction",
"user__{}".format(get_user_model().USERNAME_FIELD),
)


@admin.register(models.LineItem)
class LineItemAdmin(admin.ModelAdmin):
date_hierarchy = "created_at"
list_display = ("user", "payment", "created_at", "title", "amount")
raw_id_fields = ("user", "payment")
search_fields = ("title",)
search_fields = ("title", "user__{}".format(get_user_model().USERNAME_FIELD))
12 changes: 10 additions & 2 deletions user_payments/user_subscriptions/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.contrib.auth import get_user_model

from user_payments.exceptions import UnknownPeriodicity
from . import models
Expand All @@ -24,10 +25,14 @@ class SubscriptionAdmin(admin.ModelAdmin):
"paid_until",
"renew_automatically",
)
list_filter = ("renew_automatically",)
list_filter = ("renew_automatically", "code")
radio_fields = {"periodicity": admin.HORIZONTAL}
raw_id_fields = ("user",)
search_fields = ("title",)
search_fields = (
"title",
"code",
"user__{}".format(get_user_model().USERNAME_FIELD),
)

def get_inline_instances(self, request, obj=None):
if obj is None:
Expand All @@ -47,3 +52,6 @@ def save_model(self, request, obj, form, change):
class SubscriptionPeriodAdmin(admin.ModelAdmin):
list_display = ("subscription", "starts_on", "ends_on", "line_item")
raw_id_fields = ("subscription", "line_item")
search_fields = [
"subscription__{}".format(field) for field in SubscriptionAdmin.search_fields
]

0 comments on commit c93ad94

Please sign in to comment.