diff --git a/BaseDRF/settings.py b/BaseDRF/settings.py index f2a5c3d..eae7067 100644 --- a/BaseDRF/settings.py +++ b/BaseDRF/settings.py @@ -37,6 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'notification.apps.NotificationConfig' ] MIDDLEWARE = [ diff --git a/notification/__init__.py b/notification/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notification/admin.py b/notification/admin.py new file mode 100644 index 0000000..ff4bb34 --- /dev/null +++ b/notification/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from notification.models import * +admin.site.register(UserNotification) +admin.site.register(Notification) \ No newline at end of file diff --git a/notification/apps.py b/notification/apps.py new file mode 100644 index 0000000..a29a035 --- /dev/null +++ b/notification/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class NotificationConfig(AppConfig): + name = 'notification' + def ready(self): + from . import signals \ No newline at end of file diff --git a/notification/migrations/__init__.py b/notification/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notification/models.py b/notification/models.py new file mode 100644 index 0000000..8baa700 --- /dev/null +++ b/notification/models.py @@ -0,0 +1,18 @@ +from django.db import models +from django.contrib.auth.models import User +class UserNotification(models.Model): + user = models.OneToOneField(to=User,on_delete=models.CASCADE) + +class Notification(models.Model): + user_notification = models.ForeignKey(to=UserNotification,on_delete=models.CASCADE) + TYPE_SMS = 'sms' + TYPE_EMAIL = 'email' + TYPE_IN_APP = 'In app' + + TYPES = ( + (TYPE_SMS, 'sms'), + (TYPE_EMAIL, 'email'), + (TYPE_IN_APP, 'In app'), + ) + + notif_type = models.CharField(max_length=10,choices=TYPES) \ No newline at end of file diff --git a/notification/serializers.py b/notification/serializers.py new file mode 100644 index 0000000..c959777 --- /dev/null +++ b/notification/serializers.py @@ -0,0 +1,15 @@ +from django.db import models +from rest_framework import fields,serializers + + +class NotificationInputsSerializer(serializers.Serializer): + TYPE_SMS = 'sms' + TYPE_EMAIL = 'email' + TYPE_IN_APP = 'In app' + + TYPES = ( + (TYPE_SMS, 'sms'), + (TYPE_EMAIL, 'email'), + (TYPE_IN_APP, 'In app'), + ) + notif_type = fields.ChoiceField(choices=TYPES) \ No newline at end of file diff --git a/notification/signals.py b/notification/signals.py new file mode 100644 index 0000000..9f2f7c9 --- /dev/null +++ b/notification/signals.py @@ -0,0 +1,10 @@ +from django.dispatch import receiver +from django.db.models.signals import post_save +from django.contrib.auth.models import User +from notification.models import UserNotification + + +@receiver(post_save, sender=User) +def auto_create_user_notification(sender, instance, created, **kwargs): + if created: + UserNotification.objects.create(user=instance) \ No newline at end of file diff --git a/notification/tests.py b/notification/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/notification/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/notification/views.py b/notification/views.py new file mode 100644 index 0000000..e2102f8 --- /dev/null +++ b/notification/views.py @@ -0,0 +1,10 @@ +from django.contrib.auth.models import Permission +from django.shortcuts import render +from rest_framework import serializers +from rest_framework.generics import CreateAPIView +from .serializers import NotificationInputsSerializer +class Notification(CreateAPIView): + serializer_class = NotificationInputsSerializer + # Permission_classes = ? + def perform_create(self, serializer): + return super().perform_create(serializer)