Reputation: 1532
I have the following structure:
class FlowerSpecies(models.Model):
pass
class Months(models.Model):
flower_species = models.ForeignKey(FlowerSpecies)
month_idx = models.IntegerField()
In words, I have a bunch of flower species each of which can grow in certain months only.
How can I now use filter to query for all the species that grow in June for example?
thanks for help!
Upvotes: 0
Views: 50
Reputation: 26921
Should be able to do that with
FlowerSpecies.objects.filter(months__month_idx=6) #single month
FlowerSpecies.objects.filter(months__month_idx__in=(1,2,3)) #multiple months
See Django Making Queries documentation page for details
Upvotes: 1
Reputation: 3800
FlowerSpecies.objects.filter(months__month_idx=6)
Read up on the queries documentation, these things are well documented.
Upvotes: 1