Y
Y
YraganTron2017-03-15 12:54:07
Django
YraganTron, 2017-03-15 12:54:07

How to add an action when creating a new element via admin.StackedInline(Django)?

сlass ThreadInLine(admin.StackedInline):
    model = Comment
    extra = 1
    fields = ['comments_tittle', 'comments_text', 'comments_image']


class ThreadAdmin(MyModelAdmin):
    inlines = [ThreadInLine]
    fields = ['board', 'thread_tittle', 'thread_text', 'thread_image']
    search_fields = ['thread_tittle', 'id']
    list_filter = ('board__board_shortcut',)

    def save_model(self, request, obj, form, change):
        if change is False:
            board = Board.objects.get(board_shortcut=obj.board)
            board.board_posts += 1
            board.save()
        obj.save()

When creating a thread through the admin panel, I spin the counter I need, now I would also like to spin the same counter when creating a new comment through the admin panel, but I understand that there is no save_model method in ThreadInLine, hence the question of how to make the counter spin when adding comments ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question