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
- Mask sensitive data from logger by agusmakmun 2 weeks, 6 days ago
- Template tag - list punctuation for a list of items by shapiromatron 1 year, 2 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 3 months ago
- Serializer factory with Django Rest Framework by julio 1 year, 10 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 10 months ago
Comments
Please login first before commenting.