-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRF generic views not fire post_save signal #9394
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, |
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? |
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 |
Yup, I have done the registration in app.py and this code works fine. I just don't think it's clean enough. |
Yeah, the best practice to call the signals, is write a custom signals like Ever the instance call the Can you put your |
Yeah, there are mine
singals.py
|
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?
|
I'm sorry I'm in a drunken state. |
However, the signals works fine right? If you create manually (maybe from django shell) a Menu object instance, the signals trigger correctly? |
Yup, It's working for now.
|
So, this isn't a best practice 😞
Can you put here the serializer code? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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.
The text was updated successfully, but these errors were encountered: