Edit the code of module in venv during docker build in Django + React app
I have React as frontend and Django with Django REST Framework working as API. And the issue is I changed several lines of code in module I installed for Django app. Obviously, during Docker build those changes aren't saved. Because .venv folder for virtual environment isn't copied to container. I'm asking a way to make changes to module in .venv
folder during build. The number of changes isn't huge. Only two lines.
The module is django-rest-multiple-models==2.1.3
(https://pypi.org/project/django-rest-multiple-models/)
In drf_multiple_model
folder which is I believe a main folder of the module in .venv
I changed following(lines 196-207):
def get_label(self, queryset, query_data):
"""
Gets option label for each datum. Can be used for type identification
of individual serialized objects
"""
if query_data.get('label', False):
return query_data['label']
elif self.add_model_type:
try:
return queryset.model._meta.verbose_name
except AttributeError:
return query_data['queryset'].model._meta.verbose_name
There was __name__
instead of verbose_name
The solution is much simpler than it looked for me at first. Use OOP:
- Inherit required module's class.
- Override the required method.
- Use the overridden class.