'Need to execute my SQL queries in my model to display the result as API in django
Model
class Consolidated(models.Model):
emp_name=models.ForeignKey(Users,on_delete=CASCADE)
proj_name=models.ForeignKey(Project, on_delete=CASCADE)
custom_name=models.ForeignKey(Client,on_delete=CASCADE)
Cons_date=models.ForeignKey(Add_Timelog, on_delete=CASCADE)
bill_no_bill=models.ForeignKey(Users,related_name="billable_and_non_billable+", on_delete=CASCADE)
hour_spent = models.ForeignKey(Add_Timelog,related_name="hour_spent", on_delete=CASCADE)
def __str__(self):
return str(self.emp_name)
viewset
permission_classes=(permissions.IsAdminUser,)
queryset = models.Consolidated.objects.raw("select public.App_add_job.id, employee_name, billable_and_non_billable, client_id, project_id from public.App_add_job join public.App_users on public.App_add_job.employee_name_id = public.App_users.id")
serializer_class=serializers.Consolidated_serializers
I have a sql query updated in my viewset and i dont know how to run that query in my API model to display the table values in the api. kindly help me to change the code for the model to execute the sql queries in that Consolidated model.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
