Hello, I am using DRF to develop an API around a set of databases which all have the same tables. These databases are listed out in my Django settings file, along with the 'default' database which is used for Django's admin tables (not exposed to the API).
I have run into an issue when using a ModelSerializer() and an APIView() for POST and PUT methods. For the GET method, I was able to specify the database by passing in a queryset to the serializer that specifies the database I need. serializer = MySerializer(data=MyModel.objects.using(database).all(), > many=True) > This works perfectly well. However, I can't seem to find a way of doing this for the POST and PUT methods. The first thing I tried was to subclass the ModelSerializer() class, and made my own create() and update() functions. However, the issue seems to be with the is_valid() function of the serializer class. I've looked through the base DRF code and I can't seem to understand why the is_valid() function would need to know about the database and not just the Model in question. The error I always get is: MySQLdb._exceptions.ProgrammingError: (1146, "Table 'default.mymodel' > doesn't exist") > I was hoping someone might have a solution to this issue that doesn't involve me rewriting all of the validation myself. For the record, I've seen this post on StackOverflow: https://stackoverflow.com/questions/25690789/django-rest-framework-multiple-database The accepted answer does not work and the option of using routers won't work for me either, as all of the models apply to multiple databases (we have databases for multiple clients that are all identical, and I need the API to work for all databases). Thanks. -Jared -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
