I
I
Ilya2016-03-16 11:05:18
PostgreSQL
Ilya, 2016-03-16 11:05:18

How to auto increment in django?

How to properly autoincrement in django?
It is necessary that each category has its own counter of articles.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2016-03-16
@nuBacuk

articles_in_category = Article.objects.filter(category=category).count()

or
category.articles_set.count()

U
un1t, 2016-03-16
@un1t

Hang the post_save, post_delete signal on the article. Update the counter in the handler.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question