C
C
ckatala2019-04-21 12:30:48
Django
ckatala, 2019-04-21 12:30:48

How to edit the value through the admin panel?

Good time of the day!
Tell me how to change the value through the admin panel
For example, there is a request to display publications for a certain period
There is a filtering by the number of likes

qs = self.get_published()
qs = qs.filter(total_votes__gt=15)

How can I change the value of 15 in the admin panel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
denissurkov, 2019-04-21
@denissurkov

You can make constants:
-> There is a Constant model: title - the name of the constant (unique, text) , value - the value of the constant (null, text)
-> In the code:

constant, created = Constant.objects.get_or_create(title="MIN_LIKES_COUNT")

if created: constant.value = "15"  # По дефолту, чтобы не было ошибок
qs = qs.filter(total_votes__gt=int(constant.value))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question