Skip to content
Advertisement

Raw query results multiplies many times when I use INNER JOIN in Django

I can’t figure it out why my raw query multiplies the result as many time as the number of users. I’m using INNER JOIN and I bonded two objects so I really can’t get it. (I’m not experienced in Django Query Language so I’m using raw query).

views.py

If I’m using Django ORM I get the same result

models.py

Advertisement

Answer

Here is a simple example of how to use the ORM that you can adapt to your case:

Assume we have two models, a Country and a City like so:

We can use the Django ORM as follows:

Also, it looks like you are just passing a Projeckt instance to your template. So you really don’t need the ORM, instead you can do something like:

I’ll also briefly add it appears you have reversed the profile-projekt relation – as it stands a profile can only have one projekt, but a projekt can have many profiles – not sure if that was intended.

views.py

And then in your template: stressz/index.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement