Guest User

Untitled

a guest
Jan 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. models.py
  2. class Post(models.Model):
  3. title = models.CharField(max_length=100)
  4. tag = models.CharField(max_length=3)
  5. is_enabled = models.BooleanField(default=False)
  6.  
  7. admin.py
  8. class PostAdmin(admin.ModelAdmin):
  9. list_display = ['id', 'title', 'tag', 'is_enabled']
  10. list_display_links = None
  11. readonly_fields = ['id', 'title', 'tag']
  12.  
  13. actions = ['enable_selected', 'disable_selected']
  14.  
  15. def enable_selected(self,requst,queryset):
  16. queryset.update(is_enabled=True)
  17.  
  18. def disable_selected(self,requst,queryset):
  19. queryset.update(is_enabled=False)
  20.  
  21. enable_selected.short_description = "Enable the selected Post"
  22. disable_selected.short_description = "Disable the selected Post"
  23.  
  24. list_display = ['is_enabled']
Add Comment
Please, Sign In to add comment