Tweet django's saved objects
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


What does it do?

Tweet if a model has been saved. Useful to announce news, blogposts, etc.

How does it work?

  • notification via django service
  • shortens url with googl (via python-googl)
  • uses package twitter to tweet the notification
  • remember that an instance has been tweeted (via djangos contentype/generic foreign keys), so notifications are only sent once


I developed and tested this app (only) using Python 2.6 and Django trunk (1.3-beta atm).

Unfortunately python-googl seems to be broken/uninstallable in pypi, so you might need to it it manually: pip install hg+

twitter should get installed with this package.

How to use it

  1. Install, add tweet to your INSTALLED_APPS.

  2. get the oauth token/secret and add it to your

     $ ./ tweet_oauth
     Hi there! We're gonna get you all set up to use tweet_saved.
     In the web browser window that opens please choose to Allow
     access. Copy the PIN number that appears on the next page and paste or
     type it here:
     Please enter the PIN: 1234567
     Please add
     TWEET_SAVED_OAUTH_TOKEN = 'xxxxxxxxx'
     to your
  3. Register your model

     from tweet import tweeter
     class MyModel(models.model):
  4. if not present, add a method get_absolute_url to your model.

  5. recommended steps (but not required): Add a property twitter_message to your model to define the message to tweet. This message will automatically shrinked to fit into the 140 character limit.

    If this method is not defined, the object is simply converted to string.

    This is the twitter_message of my object, augmented with hashtags (using the tags from django-tagging):

     def twitter_message(self):
         reo = re.compile('(%s)' % '|'.join([ for x in self.tag_objects]), flags=re.IGNORECASE)
         return 'Blog: ' + re.sub(reo, '#\g<1>', self.headline)

    Add a method may_tweet returning a bool, if you want to delay the tweet, i.e. wait until the object is marked as public.


     def may_tweet(self):
         return self.published is not None and <
  6. If you want to keep track of the shortened urls, get a Google/Googl key, and add it to your

    GOOGL_KEY = 'xxxx'


  • add tests
  • document the code
  • add an option to tweet "saved" multiple times


If you fork the code (according to create a new project/app), please remember to change the CONSUMER_KEY and the CONSUMER_SECRET.


For anything like the above, contact me/send pull requests, etc.