feature/pedimentos-correccion-partidas
This commit is contained in:
18
api/notificaciones/migrations/0002_notificacion_datos.py
Normal file
18
api/notificaciones/migrations/0002_notificacion_datos.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.3 on 2026-05-26 13:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('notificaciones', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='notificacion',
|
||||
name='datos',
|
||||
field=models.JSONField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
@@ -21,6 +21,7 @@ class Notificacion(models.Model):
|
||||
|
||||
|
||||
mensaje = models.TextField(help_text="Mensaje de la notificación")
|
||||
datos = models.JSONField(null=True, blank=True)
|
||||
fecha_envio = models.DateTimeField(blank=True, null=True, help_text="Fecha de envío de la notificación")
|
||||
created_at = models.DateTimeField(auto_now_add=True, help_text="Fecha de creación de la notificación")
|
||||
visto = models.BooleanField(default=False, help_text="Indica si la notificación ha sido vista")
|
||||
|
||||
@@ -16,10 +16,11 @@ class NotificacionSerializer(serializers.ModelSerializer):
|
||||
'tipo',
|
||||
'dirigido',
|
||||
'mensaje',
|
||||
'datos',
|
||||
'fecha_envio',
|
||||
'created_at',
|
||||
'visto'
|
||||
]
|
||||
read_only_fields = ['id', 'created_at', 'tipo', 'dirigido', 'fecha_envio', 'mensaje']
|
||||
read_only_fields = ['id', 'created_at', 'tipo', 'dirigido', 'fecha_envio', 'mensaje', 'datos']
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.response import Response
|
||||
|
||||
from .models import Notificacion, TipoNotificacion
|
||||
from .serializers import NotificacionSerializer, TipoNotificacionSerializer
|
||||
@@ -45,3 +47,11 @@ class NotificacionViewSet(viewsets.ModelViewSet):
|
||||
serializer.save()
|
||||
return
|
||||
raise PermissionDenied("No tienes permiso para crear notificaciones para otros usuarios")
|
||||
|
||||
@action(detail=False, methods=['get'], url_path=r'by-task/(?P<task_id>[^/.]+)')
|
||||
def by_task(self, request, task_id=None):
|
||||
"""Recupera la notificación de una tarea de auditoría por su task_id (Celery)."""
|
||||
notif = self.get_queryset().filter(datos__task_id=task_id).first()
|
||||
if not notif:
|
||||
return Response({'detail': 'No encontrada.'}, status=status.HTTP_404_NOT_FOUND)
|
||||
return Response(self.get_serializer(notif).data)
|
||||
|
||||
Reference in New Issue
Block a user