Im very new to Django, struggling to find the answer Im looking for. Please bear with me.
In my app/urls.py file I have
router = routers.DefaultRouter()
router.register(r'drugs', views.DrugViewSet)
In my views.py file I have
class DrugViewSet(viewsets.ModelViewSet):
queryset = Drug.objects.all().order_by('name')
serializer_class = DrugSerializer
And my DrugSerializer class looks like
class DrugSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Drug
fields = ('id', 'name', 'description', 'recommended_dose_mg', 'count', 'create_date', 'update_date')
So when I do a GET on /drugs, I correctly get the list of drugs. And when I take a UUID (primary key) on a specific drug and do a GET on /drugs/<primary_key>, it correctly pulls the specific drug.
However, I want the GET on /drugs/<primary_key> to display different data. I want to join it with another model that I have and return a new json response. How exactly would I do this?