-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from PetrDlouhy/overridability
Increase overridability
- Loading branch information
Showing
2 changed files
with
52 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,53 @@ | ||
from django.contrib import admin | ||
from django.urls import reverse | ||
from django.utils.html import format_html | ||
|
||
from .models import Referral, ReferralResponse | ||
|
||
admin.site.register( | ||
Referral, | ||
list_display=[ | ||
|
||
@admin.register(Referral) | ||
class ReferralAdmin(admin.ModelAdmin): | ||
list_display = [ | ||
"user", | ||
"code", | ||
"label", | ||
"redirect_to", | ||
"target_content_type", | ||
"target_object_id" | ||
], | ||
readonly_fields=["code", "created_at"], | ||
list_filter=["target_content_type", "created_at"], | ||
search_fields=["user__first_name", "user__last_name", "user__email", "user__username", "code"] | ||
) | ||
"target_object_id", | ||
"url", | ||
] | ||
readonly_fields = ["code", "created_at"] | ||
list_filter = ["target_content_type", "created_at"] | ||
search_fields = ["user__first_name", "user__last_name", "user__email", "user__username", "code"] | ||
autocomplete_fields = ["user"] | ||
|
||
|
||
admin.site.register( | ||
ReferralResponse, | ||
list_display=[ | ||
@admin.register(ReferralResponse) | ||
class ReferralResponseAdmin(admin.ModelAdmin): | ||
list_display = [ | ||
"referral", | ||
"session_key", | ||
"user", | ||
"ip_address", | ||
"action" | ||
], | ||
readonly_fields=["referral", "session_key", "user", "ip_address", "action"], | ||
list_filter=["action", "created_at"], | ||
search_fields=["referral__code", "referral__user__username", "ip_address"] | ||
) | ||
"action", | ||
"target_object_link", | ||
] | ||
readonly_fields = ["referral", "session_key", "user", "ip_address", "action", "target_object_link"] | ||
list_filter = ["action", "created_at"] | ||
search_fields = [ | ||
"referral__code", | ||
"referral__user__email", | ||
"referral__user__username", | ||
"referral__user__first_name", | ||
"referral__user__last_name", | ||
"user__email", | ||
"user__username", | ||
"user__first_name", | ||
"user__last_name", | ||
"ip_address", | ||
] | ||
|
||
def target_object_link(self, obj): | ||
if obj.pk and obj.target: | ||
admin_link = reverse("admin:%s_%s_change" % (obj.target_content_type.app_label, obj.target_content_type.model), args=(obj.target.pk,)) | ||
return format_html('<a href="{}">{}</a>', admin_link, obj.target.__str__()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters