25 lines
826 B
Python
25 lines
826 B
Python
|
|
from django.contrib import admin
|
||
|
|
|
||
|
|
from .models import Notification, NotificationRead
|
||
|
|
|
||
|
|
|
||
|
|
@admin.register(Notification)
|
||
|
|
class NotificationAdmin(admin.ModelAdmin):
|
||
|
|
list_display = ("title", "user", "created_at")
|
||
|
|
list_filter = ("created_at",)
|
||
|
|
search_fields = ("title", "body", "user__phone")
|
||
|
|
|
||
|
|
def get_form(self, request, obj=None, **kwargs):
|
||
|
|
form = super().get_form(request, obj, **kwargs)
|
||
|
|
form.base_fields["user"].help_text = "خالی بگذار تا برای همهی کاربران نمایش داده شود."
|
||
|
|
return form
|
||
|
|
|
||
|
|
|
||
|
|
@admin.register(NotificationRead)
|
||
|
|
class NotificationReadAdmin(admin.ModelAdmin):
|
||
|
|
list_display = ("user", "notification", "read_at")
|
||
|
|
search_fields = ("user__phone", "notification__title")
|
||
|
|
|
||
|
|
def has_add_permission(self, request):
|
||
|
|
return False
|