Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement non-database backed models in Django?

I have an existing Django application with a pretty typical model implementation that's backed by a database. My task is to change this model so that instead of fetching the information from a database, it now fetches it from a service (e.g., via HTTP). Because there is existing code which already makes use of this model, it would be nice to maintain the same model interface so that it continues to behave like a typical Django model.

This raises a few of questions:

  • Is it possible to do this without having to re-write the interface from scratch to make it look like Django's model interface? (This stackoverflow question would seem to suggest otherwise: Django MVC pattern for non database driven models?)

  • Would writing a custom manager for this model be an appropriate approach (or have I misunderstood the role of the manager)?

  • Due to the service-backed nature of the new model, caching will be much more important than before. Is this something that should be implemented at the model level?

like image 364
Michael Wehner Avatar asked Aug 11 '10 21:08

Michael Wehner


People also ask

Can Django work without database?

However, while you can use django with no database, the object-relational mapper is pretty much its first and foremost advertised feature. Django was designed to produce database-backed web sites, so if you're not going to use a database you might end up dealing with a bunch of unnecessary hassle.

Is Django models a database?

A Django model is a table in your database.

Can you use Django without models?

Yes that is possible, but a lot of ways how Django can help with webdevelopment are based on its models.


1 Answers

Have a look at django-roa. From the sound of it, it might be exactly what you are looking for.

like image 133
Benjamin Wohlwend Avatar answered Oct 13 '22 23:10

Benjamin Wohlwend