@@ -50,16 +50,16 @@ class CustomUserAdmin(admin.ModelAdmin):
50
50
class PostAdmin (admin .ModelAdmin ):
51
51
fieldsets = [
52
52
('Post' , {'fields' : ('datetime' , 'category' ,'author' , 'title' ,
53
- 'text' , 'image' , 'tag' , 'show' ),
53
+ 'text' , 'image' , 'tag' , 'show' , 'active' ),
54
54
}),
55
55
]
56
56
# fields = ('category','author', 'title', 'text', 'image', 'tag', 'datetime', 'show')
57
57
58
58
inlines = (CommentInline , LikeInline , TagPostInline )
59
59
list_display = ('title' , 'author' , 'category' , 'get_tags' ,
60
- 'datetime' , 'show' , 'get_count_likes' ,
60
+ 'datetime' , 'show' , 'active' , ' get_count_likes' ,
61
61
'get_count_dislikes' )
62
- list_filter = ('author' , 'category' , 'show' , 'tag' , 'datetime' )
62
+ list_filter = ('author' , 'category' , 'show' ,'active' , 'tag' , 'datetime' )
63
63
search_fields = ('author' , 'tag' , 'category' , 'title' )
64
64
65
65
def show_posts (self , request , queryset ):
@@ -73,7 +73,20 @@ def dont_show_posts(self, request, queryset):
73
73
self .message_user (request , f'{ updated } پست نمایش داده نمی شود.' , messages .ERROR )
74
74
75
75
dont_show_posts .short_description = 'عدم نمایش پست ها'
76
- actions = (show_posts , dont_show_posts )
76
+
77
+ def active_posts (self , request , queryset ):
78
+ updated = queryset .update (active = True )
79
+ self .message_user (request , f'{ updated } پست فعال شد.' , messages .SUCCESS )
80
+
81
+ active_posts .short_description = 'فعال کردن پست ها'
82
+
83
+ def deactive_posts (self , request , queryset ):
84
+ updated = queryset .update (active = False )
85
+ self .message_user (request , f'{ updated } پست غیرفعال شدند.' , messages .ERROR )
86
+
87
+ deactive_posts .short_description = 'غیرفعال کردن پست ها'
88
+
89
+ actions = (show_posts , dont_show_posts , active_posts , deactive_posts )
77
90
78
91
79
92
@admin .register (Comment )
0 commit comments