1

I have models like this:

class Education(models.Model):
    title = models.CharField(default=None, max_length=100)
    content = models.TextField(default=None)
    price = models.ManyToManyField(Price)

class Price(models.Model):
    cost = models.CharField(default=None, max_length=20)
    created_at = models.DateTimeField(auto_now=True, null=True, blank=True)

And i want to inner join between two tables and access to all fields of both.

reza_khalafi
  • 6,230
  • 7
  • 56
  • 82

1 Answers1

1

We can achieve like this,

Education.objects.filter(price__in=Price.objects.all()).select_related('Price').values_list('title', 'content', 'price__cost', 'price__created_at')

starboy_jb
  • 899
  • 1
  • 6
  • 13
  • how i can group by based on Education.id with latest cost parameter that inserted. It means i addition to get list of grouped educations, i wanna get the latest cost that inserted for it. – reza_khalafi Nov 17 '21 at 11:19
  • https://stackoverflow.com/q/70004553/3319132 – reza_khalafi Nov 17 '21 at 12:37