Skip to content

Allow search and filter in Django Admin for Message model #7615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion readthedocs/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

from messages_extends.admin import MessageAdmin
from messages_extends.models import Message
from rest_framework.authtoken.admin import TokenAdmin

from readthedocs.core.models import UserProfile
from readthedocs.projects.models import Project
from rest_framework.authtoken.admin import TokenAdmin


# Monkeypatch raw_id_fields onto the TokenAdmin
Expand Down Expand Up @@ -101,6 +104,32 @@ class UserProfileAdmin(admin.ModelAdmin):
raw_id_fields = ('user',)


class MessageAdminExtra(MessageAdmin):
list_display = [
'user',
'organizations',
'message',
'created',
'read',
]
list_filter = [
'read',
]
search_fields = [
'user__username',
'message',
'user__organizationowner__organization__slug',
]

def organizations(self, obj):
return ', '.join(
organization.slug
for organization in obj.user.owner_organizations.all()
)


admin.site.unregister(User)
admin.site.register(User, UserAdminExtra)
admin.site.register(UserProfile, UserProfileAdmin)
admin.site.unregister(Message)
admin.site.register(Message, MessageAdminExtra)