Clone wiki

django-roa / Home

Django-ROA (Resource Oriented Architecture)

Use Django's ORM to model remote API resources.

Not very clear? A picture is worth a thousand words:

Django-ROA diagram

In this diagram, the repository can be whatever you want, the only requirement is that it handles standard HTTP requests. As a developer all you have to do next is to use Django's ORM in your Django application (connectors are part of Django-ROA).

If you know how ActiveRecord works (from RoR), that's very close to it.

What problems does it solve?

Here are some ideas:

  • data handled by a data warehouse (SOA)
  • multiple database (as you can customize URLs per model)
  • schema-less backend (e.g. CouchDB speaks HTTP)
  • access a remote API with your own models (and with django's built-in admin!)
  • plug it on top of an RDF triple store (probably my next pony)
  • your crazy use-case? ;-)

A basic Twitter example

The complete example is available in source code examples. First let's define some models with URLs from Twitter's API:

class User(Model):
    name = models.CharField(max_length=50)
    screen_name = models.CharField(max_length=50)
    description = models.TextField()

    def get_resource_url_list():
        return u''

class Tweet(Model):
    text = models.TextField()
    source = models.CharField(max_length=50)
    user = models.ForeignKey(User)

    def get_resource_url_list():
        return u''

Now we can launch a Django shell and test our models:

$ python shell
>>> from twitter_roa.models import User, Tweet
>>> tweets = Tweet.objects.all()
>>> atweet = tweets[0]
>>> print atweet.text
Uhm can I get a boyfriend with muscles and no bullshit. Yumm. Xoxo
>>> print
Jacob Maldonado

It works! But even more interesting, you can use your lovely Django's built-in admin with your new models:

Tweets in your Django admin

Now you'll even be able to clic on users to go to the Django's admin view. And so on.

Getting started


Need help?


You can find me in as david`bgk or through my website.

Declaring bugs

Go to the issue tracker, verify you request doesn't exist and then submit it.

Fixing bugs

Use the power of Mercurial Queues and submit your patch(es). Help is really appreciated :-)