6

I have been building a Django Application which consumes data from an expansive REST-like API. The API was built using .NET (yuck! not my choice), and since I would rather gouge out my eyeballs than learn Microsoft tools (I'm a *nix/OSX guy), and since I do not want the front-end to affect the API or vice-versa, I elected to build the front-end using Django on another server.

The Django site acts as a middleman between the main DB/API and the End-User. None of the data from the API is persisted in the Django site, it simply reformats/displays said data in a nice human-readable format. Now that I have built my API client and all of my views, I am looking to create a report builder.

Are there any apps out there already that can create Transitory Models to represent objects from an API call? I would like to be able to create relations between JSON/XML data received from the API, but not need to duplicate the DB structure in my Django site, that would be redundant.

The end goal would be to be able to have a user create/save custom filtered reports based on requests from the data API. Any suggestions would be greatly appreciated. (please don't respond with 'just duplicate the models in Django, and insert the data retrieved from the API'. That completely would completely nullify the point of having the DB/API running on a different server than the front-end.

Note - I have looked at neithere's Dark, but with the lack of documentation on it, and the lack of documentation on the dependent 'docu' library, I really have no idea if it is any good to me. If you have any examples of how to use them to solve this problem, please do tell :)

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
G. Shearer
  • 2,175
  • 17
  • 19
  • possibly related: http://stackoverflow.com/questions/1290891/django-mvc-pattern-for-non-database-driven-models – Yuval Adam Oct 04 '12 at 17:18
  • I am investigating using django-tables: [django-tables2](http://django-tables2.readthedocs.org/en/latest/index.html) seems like i might be able to use that to achieve my goals – G. Shearer Oct 04 '12 at 18:47
  • cool, but not really useful to solving my problem – G. Shearer Oct 05 '12 at 20:14

2 Answers2

2

Here's a hack I can think of that might work.

First, define a dummy database backend in addition to any other database you have:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase'
    },
    'dummy': {
        'ENGINE': 'django.db.backends.dummy',
        'NAME': 'dummy'
    }

Then define your non-db-model as you would. From there you have the using functionality that can tell Django to use a specific backend for that call, and request to use the dummy backend:

objs = YourModel.objects.using('dummy').all()

Alternatively you just might also be able to get away with just creating the objects without ever save()'ing them.

Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
  • interesting idea. maybe the solution i am really looking for is a custom db backend (similar to an InMemoryStore from Cocoa's Core Data) – G. Shearer Oct 04 '12 at 18:11
  • I see documentation for a dummy cache backend, but not a dummy database backend. Where is this documented? – shacker Oct 05 '12 at 06:46
  • 1
    as far as i understand, the dummy database backend will do us no good unless you make your own version, its just a default dummy class. read through the code that defines the class, it throws an exception on most all methods (to inform you that you have not setup a db) – G. Shearer Oct 05 '12 at 20:13
1

I actually ended up finding a solution to this problem, very much later lol.

Thank you djangopackages.com!!!

Apparently there is a term for what I was looking for, ROA (Resource Oriented Architecture). This is a paradigm from the world of Ruby on Rails. There is a django app which handles this called django-roa

so i will experiment with that, thanks for the attempt @Yuval Adam

Elijah
  • 82
  • 8
G. Shearer
  • 2,175
  • 17
  • 19