import changes in notification

This commit is contained in:
2025-10-08 11:13:01 +03:30
parent cad4ccbe4b
commit f1a209a166
9 changed files with 104 additions and 25 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.0 on 2025-10-08 07:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notification', '0002_notification_device'),
]
operations = [
migrations.AddField(
model_name='notification',
name='delivering_type',
field=models.CharField(choices=[('general', 'GENERAL'), ('private', 'PRIVATE')], max_length=150, null=True),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.0 on 2025-10-08 07:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('notification', '0003_notification_delivering_type'),
]
operations = [
migrations.AlterField(
model_name='notification',
name='delivering_type',
field=models.CharField(choices=[('general', 'GENERAL'), ('private', 'PRIVATE')], default='private', max_length=150, null=True),
),
]

View File

@@ -31,6 +31,10 @@ class Notification(BaseModel):
choices=NOTIFICATION_TYPES,
default='system'
)
delivering_type = models.CharField(max_length=150, null=True, choices=(
('general', 'GENERAL'),
('private', 'PRIVATE'),
), default='private')
is_read = models.BooleanField(default=False)
delivered = models.BooleanField(default=False)

View File

@@ -9,6 +9,7 @@ from rest_framework.response import Response
from rest_framework import viewsets
from rest_framework import status
from django.db import transaction
from django.db.models import Q
class NotificationViewSet(SoftDeleteMixin, POSDeviceMixin, DynamicSearchMixin, viewsets.ModelViewSet):
@@ -22,12 +23,26 @@ class NotificationViewSet(SoftDeleteMixin, POSDeviceMixin, DynamicSearchMixin, v
organization = self.get_device_organization()
device = self.get_pos_device()
queryset = self.queryset.filter(
device=device,
organization=organization,
delivered=False,
is_read=False
)
show_type = self.request.query_params.get('show')
if show_type == 'undelivered':
queryset = self.queryset.filter(
Q(delivering_type='general') | Q(delivering_type='private'),
device=device,
organization=organization,
delivered=False,
is_read=False,
)
elif show_type == 'unread':
queryset = self.queryset.filter(
Q(delivering_type='general') | Q(delivering_type='private'),
device=device,
organization=organization,
delivered=True,
is_read=False
)
else:
queryset = self.queryset
# paginate & response
page = self.paginate_queryset(queryset)