Replies: 11 comments
-
The class CreateModelMixin:
"""
Create a model instance.
"""
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def perform_create(self, serializer):
serializer.save() see the So, |
Beta Was this translation helpful? Give feedback.
-
Thank you. @FraCata00 . I calling
I'm just wondering if there isn't a more appropriate way to trigger this other than customizing the view and expanding CreateAPIView? |
Beta Was this translation helpful? Give feedback.
-
But have you registered the signals in the ready function of AppConfig? If you did, there's no need to call it in perform_create, trigger automatically |
Beta Was this translation helpful? Give feedback.
-
Yup, I have done the registration in app.py and this code works fine. I just don't think it's clean enough. |
Beta Was this translation helpful? Give feedback.
-
Yeah, the best practice to call the signals, is write a custom signals like Ever the instance call the Can you put your |
Beta Was this translation helpful? Give feedback.
-
Yeah, there are mine
singals.py
|
Beta Was this translation helpful? Give feedback.
-
this signals is from a project module or an application module? from django.apps import AppConfig
class PortfolioConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'settings'
def ready(self):
import settings.signals # --> the 'settings' is an application or project?
|
Beta Was this translation helpful? Give feedback.
-
I'm sorry I'm in a drunken state. |
Beta Was this translation helpful? Give feedback.
-
However, the signals works fine right? If you create manually (maybe from django shell) a Menu object instance, the signals trigger correctly? |
Beta Was this translation helpful? Give feedback.
-
Yup, It's working for now.
|
Beta Was this translation helpful? Give feedback.
-
So, this isn't a best practice 😞
Can you put here the serializer code? |
Beta Was this translation helpful? Give feedback.
-
Checklist
In the new generic view, whether it's CreateAPIView or ListCreateAPIView, it will not trigger the Django Signal receiver
Future updates should consider fixing it to work better with django!
I could achieve the goal by overriding perform_create, but geez, that's not a good way to do it.
Beta Was this translation helpful? Give feedback.
All reactions