Answer the question
In order to leave comments, you need to log in
How to make filtering one query on 5 fields of the model?
Hi everybody!
How to make a filter with one request on 5 fields of the model "accessories_material"
class Accessories(models.Model):
created_on = models.DateTimeField(u"Date of creation", auto_now_add=True, blank=True, null=True)
posted_by = models.ForeignKey( User, blank=True, null=True)
edited_by = models.CharField(max_length=255, blank=True)
accessories_plot = models.ForeignKey(Accessories_plot, verbose_name='Plot')
accessories_material = models.ForeignKey(Accessories_material)
accessories_material2 = models. ForeignKey(Accessories_material)
accessories_material3 = models.ForeignKey(Accessories_material)
accessories_material4 = models.ForeignKey(Accessories_material)
accessories_material5 = models.ForeignKey(Accessories_material)
Answer the question
In order to leave comments, you need to log in
See select_related()
Example: qs = Accessories.objects.all().select_related('accessories_material', 'accessories_material2', 'accessories_material3', 'accessories_material4', 'accessories_material5')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question