Assume you have a model called Delegate and you want to tweet whenever a new Delegate registers, the code above will do this. You need to install python-twitter.
1 2 3 4 5 6 7 8 9 10 11 12 | import twitter
from django.db.models.signals import post_save
def tweetit(sender,**kwargs):
"""
extract relevant info and tweet it
"""
if kwargs['created']:
t = twitter.Api(settings.TWITTER_USER, settings.TWITTER_PASSWORD)
t.PostUpdate("%s has registered as a delegate" %(kwargs['instance']))
post_save.connect(tweetit, sender=Delegate)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.