prateek gupta
2018-11-21 08:57:47 UTC
Hi All,
I have an admin panel built on Django 2.0.6, Mysql 5.7 and Python 3.6.
Now I have written following signal code in signals.py-
from .models import MerchantStores
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender = MerchantStores, weak=False)
def ensure_store_id_exists(sender, **kwargs):
print ("check fucntion")
ex = kwargs.get("instance").store_id
print ("store id:",ex)
import requests
URL = "http://example.cloud/rmsservice/resetPin?storeId="+str(ex)
print("url:",URL)
data = {'Content-Type': 'application/json',
'app-id': 'APP_ID',
'secret-key': 'SECRET_KEY',
'aid': 'PG'}
r = requests.post(url=URL, headers=data)
response_text = r.text
print(response_text)
And in apps.py I have done following settings-
from django.apps import AppConfig
class AdminappConfig(AppConfig):
name = 'adminapp'
def ready(self):
import adminapp.signals
In above signals I am sending a post request to resetPin api.
I need to send the request once form is saved but my signal is posting
request before the save method.
I confirmed the above from server logs. Following is the logs I am getting-
[21/Nov/2018 14:18:03] "GET /jsi18n/ HTTP/1.1" 200 3185
check fucntion
store id: 1533
url: http://example/rmsservice/resetPin?storeId=1533
{"success":false,"code":"8050","message":"Merchant not
active","response":null}
[21/Nov/2018 14:18:29] "POST /adminapp/merchantstores/add/ HTTP/1.1" 302 0
[21/Nov/2018 14:18:32] "GET /adminapp/merchantstores/ HTTP/1.1" 200 12659
[21/Nov/2018 14:18:34] "GET /jsi18n/ HTTP/1.1" 200 3185
As per above log, my signal is invoked before teh save() method but it
should be after the save() method.
Can anyone please help my to find out what I am doing wrong here?
Thanks,
Prateek
I have an admin panel built on Django 2.0.6, Mysql 5.7 and Python 3.6.
Now I have written following signal code in signals.py-
from .models import MerchantStores
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender = MerchantStores, weak=False)
def ensure_store_id_exists(sender, **kwargs):
print ("check fucntion")
ex = kwargs.get("instance").store_id
print ("store id:",ex)
import requests
URL = "http://example.cloud/rmsservice/resetPin?storeId="+str(ex)
print("url:",URL)
data = {'Content-Type': 'application/json',
'app-id': 'APP_ID',
'secret-key': 'SECRET_KEY',
'aid': 'PG'}
r = requests.post(url=URL, headers=data)
response_text = r.text
print(response_text)
And in apps.py I have done following settings-
from django.apps import AppConfig
class AdminappConfig(AppConfig):
name = 'adminapp'
def ready(self):
import adminapp.signals
In above signals I am sending a post request to resetPin api.
I need to send the request once form is saved but my signal is posting
request before the save method.
I confirmed the above from server logs. Following is the logs I am getting-
[21/Nov/2018 14:18:03] "GET /jsi18n/ HTTP/1.1" 200 3185
check fucntion
store id: 1533
url: http://example/rmsservice/resetPin?storeId=1533
{"success":false,"code":"8050","message":"Merchant not
active","response":null}
[21/Nov/2018 14:18:29] "POST /adminapp/merchantstores/add/ HTTP/1.1" 302 0
[21/Nov/2018 14:18:32] "GET /adminapp/merchantstores/ HTTP/1.1" 200 12659
[21/Nov/2018 14:18:34] "GET /jsi18n/ HTTP/1.1" 200 3185
As per above log, my signal is invoked before teh save() method but it
should be after the save() method.
Can anyone please help my to find out what I am doing wrong here?
Thanks,
Prateek
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9edd586b-604b-4734-ab1d-28f7fda9d527%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9edd586b-604b-4734-ab1d-28f7fda9d527%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.