S
S
Sergey Nizhny Novgorod2017-04-20 02:30:45
Django
Sergey Nizhny Novgorod, 2017-04-20 02:30:45

How to make a filter by one field for all views?

Hello.
I would like to clarify how to do this correctly:
- the course model has a field activity_of_course = models.BooleanField(default=True, verbose_name="Is the course active?")
- the courses are displayed in 20 views
- you need to display only those courses where activity_of_course = True.
Is there some way to do this correctly instead of writing a filter in each of the 20 views?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Animkim, 2017-04-20
@Terras

https://docs.djangoproject.com/en/1.10/topics/db/m... this is what you need.

A
AlexandrBirukov, 2017-04-20
@AlexandrBirukov

alternatively, you can use a mixin for views

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question