6

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?

Community
  • 1
  • 1
Michael Wehner
  • 753
  • 2
  • 6
  • 13

1 Answers1

4

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

Benjamin Wohlwend
  • 30,958
  • 11
  • 90
  • 100
  • This is really neat, and I hadn't seen it before. Unfortunately, the service in question isn't a RESTful one, and I think I'll need the ability to use custom code to perform the work usually done by the database. Still, where one has a RESTful service they can attach their models to, this is pretty nice. – Michael Wehner Aug 11 '10 at 22:17
  • As fate would have it, I no longer need to have a non-database model in real life. As a consequence, this is a much better answer to the question I would rather have been asking anyway. Thanks! – Michael Wehner Aug 12 '10 at 15:54
  • 1
    @monkut I updated the link, but it looks like the project isn't maintained anymore, last commit is more than 5 years ago – Benjamin Wohlwend Feb 18 '19 at 15:22
  • I was looking for a way to implement a Model without a db backend, and wanted to check this out. – monkut Feb 19 '19 at 04:21