0

How would one go about taking all models from all applications in django and then expose all of them under a systematic CRUD endpoint such as api/models/**** without writing DRF Views for each model individually? In other words, how does one create a generic CRUD API for all models of a django server to quickly modify data in the database via REST?

So if we have this application file structure

application/
  /auth
    /models
      /token.py
      /other_model.py
  /shop
 /profile
 /...

It would result in the following CRUD endpoints

domain.com/api/models/auth/token
domain.com/api/models/auth/other_model
domain.com/api/models/shop/card
...

Further, these generic endpoints could allow basic filtering (by id, define return fields with a ?fields=... parameter etc.

I know about Eve but we are committed to django/DRF and we want to cut away a lot of redundant model-serializer-view verticals that offer little value for lots of code.

pascalwhoop
  • 2,984
  • 3
  • 26
  • 40
  • Found this on google: https://github.com/Brobin/drf-generators, I am not sure if this library is maintained regularly or not, but its Django version is bit old. If you no problem with that, then I think you can look into this. – ruddra Nov 19 '18 at 16:53
  • that looks like it generates code. I was aiming for a runtime generation of the classes based on a list of all models classes. Maybe something using the `type(...)` abilities of Python – pascalwhoop Nov 20 '18 at 15:32
  • https://stackoverflow.com/questions/30831731/create-a-generic-serializer-with-a-dynamic-model-in-meta – HuLu ViCa Nov 20 '18 at 21:00

0 Answers0