Added celery and rabbitmq
This commit is contained in:
@@ -2,6 +2,7 @@ from django.contrib.auth.password_validation import validate_password as django_
|
||||
from django.core.exceptions import ValidationError
|
||||
from rest_framework import serializers
|
||||
from apps.user.models import User
|
||||
from apps.tasks import send_email
|
||||
|
||||
|
||||
class RegisterSerializer(serializers.ModelSerializer):
|
||||
@@ -33,5 +34,6 @@ class RegisterSerializer(serializers.ModelSerializer):
|
||||
validated_data["password"]
|
||||
)
|
||||
|
||||
|
||||
send_email.delay(user.pk)
|
||||
|
||||
return user
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.db import models
|
||||
from apps.user.models import User
|
||||
# from django.db import models
|
||||
# from apps.user.models import User
|
||||
|
||||
class Author(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors")
|
||||
name = models.CharField(max_length=255)
|
||||
# class Author(models.Model):
|
||||
# user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors")
|
||||
# name = models.CharField(max_length=255)
|
||||
@@ -1,9 +1,9 @@
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from apps.authors.views import AuthorsViewSet
|
||||
# from apps.authors.views import AuthorsViewSet
|
||||
|
||||
urlpatterns = []
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("", viewset=AuthorsViewSet)
|
||||
urlpatterns += router.urls
|
||||
# router = DefaultRouter()
|
||||
# router.register("", viewset=AuthorsViewSet)
|
||||
# urlpatterns += router.urls
|
||||
@@ -1,20 +1,20 @@
|
||||
from rest_framework import viewsets
|
||||
# from rest_framework import viewsets
|
||||
|
||||
from apps.authors.models import Author
|
||||
from apps.authors.serializers import AuthorSerializer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
# from apps.authors.models import Author
|
||||
# from apps.authors.serializers import AuthorSerializer
|
||||
# from rest_framework import viewsets
|
||||
# from rest_framework.permissions import IsAuthenticated
|
||||
# from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
|
||||
class AuthorsViewSet(viewsets.ModelViewSet):
|
||||
queryset = Author.objects.select_related("shelf")
|
||||
serializer_class = AuthorSerializer
|
||||
# class AuthorsViewSet(viewsets.ModelViewSet):
|
||||
# queryset = Author.objects.select_related("shelf")
|
||||
# serializer_class = AuthorSerializer
|
||||
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
# authentication_classes = [JWTAuthentication]
|
||||
# permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
return self.queryset.filter(
|
||||
shelf__user_id=self.request.user.pk
|
||||
)
|
||||
# def get_queryset(self):
|
||||
# return self.queryset.filter(
|
||||
# shelf__user_id=self.request.user.pk
|
||||
# )
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from django.db import models
|
||||
|
||||
from apps.shelves.models import Shelf
|
||||
from apps.authors.models import Author
|
||||
# from apps.authors.models import Author
|
||||
from apps.user.models import User
|
||||
|
||||
class Book(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors")
|
||||
authors = models.ManyToManyField(Author, related_name="books")
|
||||
# authors = models.ManyToManyField(Author, related_name="books")
|
||||
name = models.CharField(max_length=255)
|
||||
isbn = models.CharField(max_length=13)
|
||||
11
backend/apps/tasks.py
Normal file
11
backend/apps/tasks.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from celery import shared_task
|
||||
|
||||
|
||||
@shared_task
|
||||
def send_email(user_pk):
|
||||
print(user_pk)
|
||||
|
||||
# if sended
|
||||
# zmienna info itp, jesli sie straci
|
||||
|
||||
return None
|
||||
@@ -0,0 +1,3 @@
|
||||
from config.celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
||||
11
backend/config/celery.py
Normal file
11
backend/config/celery.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.django.dev')
|
||||
|
||||
app = Celery('library')
|
||||
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
app.autodiscover_tasks()
|
||||
@@ -131,3 +131,5 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||
|
||||
STATIC_URL = "static/"
|
||||
|
||||
from config.settings.celery import *
|
||||
0
backend/config/settings/__init__.py
Normal file
0
backend/config/settings/__init__.py
Normal file
3
backend/config/settings/celery.py
Normal file
3
backend/config/settings/celery.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from config.env import env
|
||||
|
||||
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
|
||||
Reference in New Issue
Block a user