2021-06-08 03:11:27 +00:00
|
|
|
|
import django_filters
|
|
|
|
|
|
2021-06-09 12:51:31 +00:00
|
|
|
|
from common.drf.filters import BaseFilterSet
|
2023-02-01 08:43:43 +00:00
|
|
|
|
from .models import MessageContent
|
2021-06-08 03:11:27 +00:00
|
|
|
|
|
|
|
|
|
|
2021-06-09 12:51:31 +00:00
|
|
|
|
class SiteMsgFilter(BaseFilterSet):
|
|
|
|
|
# 不用 Django 的关联表过滤,有个小bug,会重复关联相同表
|
|
|
|
|
# SELECT DISTINCT * FROM `notifications_sitemessage`
|
|
|
|
|
# INNER JOIN `notifications_sitemessageusers` ON (`notifications_sitemessage`.`id` = `notifications_sitemessageusers`.`sitemessage_id`)
|
|
|
|
|
# INNER JOIN `notifications_sitemessageusers` T4 ON (`notifications_sitemessage`.`id` = T4.`sitemessage_id`)
|
|
|
|
|
# WHERE (`notifications_sitemessageusers`.`user_id` = '40c8f140dfa246d4861b80f63cf4f6e3' AND NOT T4.`has_read`)
|
|
|
|
|
# ORDER BY `notifications_sitemessage`.`date_created` DESC LIMIT 15;
|
|
|
|
|
has_read = django_filters.BooleanFilter(method='do_nothing')
|
2021-06-08 03:11:27 +00:00
|
|
|
|
|
|
|
|
|
class Meta:
|
2023-02-01 08:43:43 +00:00
|
|
|
|
model = MessageContent
|
2021-06-08 03:11:27 +00:00
|
|
|
|
fields = ('has_read',)
|