I wan’t to override the internal read query present inside my class or method. I wan’t to write generalised solution so that it should work on the class or method where I wan’t to modify the read queries.
I am trying to do using decorators, middleware and metaclasses but I am unable to access the internal read query of function.
I just wan’t to modify it to take it from read replica. but I can’t do this to all read query. I can only modify read query to take it from read replica for few class or method.
master_models.CarTransmission.objects.filter( # pylint: disable=E1101 variant_id__in=self.variant_ids ).values_list(*self.specifications, named=True)
modify this to-
master_models.CarTransmission.objects.using('replica').filter( # pylint: disable=E1101 variant_id__in=self.variant_ids ).values_list(*self.specifications, named=True)
original-
model = get_object_or_404(master_models.Model,slug=slug)
modify this to –
model = get_object_or_404(master_models.Model.objects.using('replica'),slug=slug)
The logic that I am expecting should be specific to class and method. I f i apply that on class all the method present should modify all the internal read query. Is it possible or I should go to all query and write .using(‘replica’)
pleaser don’t provide solution which work for some specific app like using routing to move it to redirect to replica as they will be going to work on whole project or on some app not specific to method or class.
Ayush Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.