Hellow.. I have a problem on django signal and instances. i have a right some code that runs a function after a certain model is created but could not use the instace filter
Help def send_sms_notifications(sender, instance, created, **kwargs): #get sender, instance, created # TODO: Lookup the reporters based on the sample point and # figure out who to send to, what to send # print sender.notes reporter = instance.taken_by point = instance.sampling_point # A temporary SMS Response # TODO: Auto generate response SMS. msg = "Your sample data is submitted sucessfully.!" # sending an sms to a submitter. thread = Thread(target=_send_sms,args=(reporter.id, msg )) thread.start() # create massage for the authorised testers. msg2 = "Test taken at site %s - %s." % (instance.sampling_point.wqmarea, instance.sampling_point) # ss = Sample.objects.filter(taken_by=reporter,sampling_point=instance.sampling_point, date_received=instance.date_received) # The instance is displayed here. print '############### %s ########' % (instance) # I can get the instace id. OK print '<<<<<<<<<<<<<<<<<<< %d' % (instance.id) sample_id = instance.id m_values = MeasuredValue.objects.filter(sample__id = sample_id) # I NEED TO GET MEASUREDVALUE WITH RESPECT TO THE SAMPLE # NO DATA IS RETURN HERE... print '----------------- %s ' % (m_values) for m_value in m_values: print "<<<<<<<<<<<<<< %s:%s" % (m_value.parameter.test_name, m_value.value) msg2 += " %s:%s" % (m_value.parameter.test_name, m_value.value) msg2 += '. Comment: %s'%(instance.notes) # figure out who to send sms to in the notifation table. notices = SmsNotification.objects.filter(sampling_point = point) for notice in notices: reporter = notice.authorised_sampler # TODO: generate a sms according the the authorised tester. # this is temp sms to authorised sampler # send the sms thread = Thread(target=_send_sms,args=(reporter.id, msg2 )) thread.start() def _send_sms(reporter_id, message_text): data = {"uid": reporter_id, "text": message_text } encoded = urllib.urlencode(data) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} try: conn = httplib.HTTPConnection("localhost:8000") # TODO: DON'T HARD CODE THIS! conn.request("POST", "/ajax/messaging/send_message", encoded, headers) response = conn.getresponse() except Exception, e: # TODO: better error reporting raise # Register to receive signals each time a Sample is saved post_save.connect(send_sms_notifications, sender=Sample) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.