P
P
paevlk20072014-09-15 12:26:45
WordPress
paevlk2007, 2014-09-15 12:26:45

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

2 answer(s)
A
Andrey K, 2014-09-15
@mututunus

https://docs.djangoproject.com/en/dev/topics/db/qu...

A
Alexey Bukin, 2014-09-21
@abukin

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 question

Ask a Question

731 491 924 answers to any question