Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - app to build reports using data retrieved from a REST-like API

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 :)

like image 457
G. Shearer Avatar asked Oct 04 '12 17:10

G. Shearer


1 Answers

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.

like image 171
Yuval Adam Avatar answered Sep 30 '22 19:09

Yuval Adam