Hi all,

I'm new to Django, but really enjoying using it so far!

What I'm trying to do is to export data from an admin interface, when a record 
is created or updated. I'm calling another web service to tell it the data on 
site [A] has changed, by using signals.

e.g.

@receiver(post_save, sender=Poll)
def notify_central_hub(sender, instance, created, **kwargs):
    if created: 

        #make a string to hold the url of the request
        url = "http://www.example.com/webservice";
        
        #place POST data in a dictionary
        post_data_dictionary = kwargs
        
        #encode the POST data to be sent in a URL
        post_data_encoded = urllib.urlencode(post_data_dictionary)
        
        #make a request object to hold the POST data and the URL
        request_object = urllib2.Request(url, post_data_encoded)
        
        #make the request using the request object as an argument, store 
response in a variable
        response = urllib2.urlopen(request_object)


I'm able to export the data this way, but I can't get the attributes of the 
full model as I would as if I was using the Django shell. Particularly 
important is the ID of an object, because without that I won't know which ID to 
update on the remote web service. That's why I'm only dealing with "created" 
objects for now.

Could someone please advise me whether I'm going about this the right way, or 
if there is actually a better way of doing this? I looked into Django 
middleware but this appears to be more for changing the output at the view 
layer, not the data layer. But if there is a better way of doing this, I'd be 
keen to find out!

Many thanks,

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/zystPhngbI0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to