I have these models
class Region (models.Model):
name = models.CharField (max_length = 255, blank = False)
class Album(TimeStampAwareModel):
title = models.CharField (max_length = 255, blank = False)
digital_release_date = models.ManyToManyField( Region, through="AlbumRegionReleaseDate", related_name="release_date_albums")
published = models.BooleanField (default = False)
.
.
class AlbumRegionReleaseDate(models.Model):
album = models.ForeignKey (Album)
region = models.ForeignKey (Region)
digital_release_date = models.DateField ()
class Meta:
ordering = ('-digital_release_date')
Suppose i have three regions i:e Europe, South Asia and North Asia
Now i want to get all "published" albums order by "digital_release_date" in Europe region?
Can anyone please tell me how to do this by SQL query?
Thanks :)
EDIT:
Sorry, my mistake! Now this should work. I tried it at home...
Album.objects.filter(
published=True,
albumregionreleasedate__region__name='Europe'
).order_by(
'albumregionreleasedate__digital_release_date'
)
Here is some help to future doubts
Hope it works now!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With