Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- models.py
- class Post(models.Model):
- title = models.CharField(max_length=100)
- tag = models.CharField(max_length=3)
- is_enabled = models.BooleanField(default=False)
- admin.py
- class PostAdmin(admin.ModelAdmin):
- list_display = ['id', 'title', 'tag', 'is_enabled']
- list_display_links = None
- readonly_fields = ['id', 'title', 'tag']
- actions = ['enable_selected', 'disable_selected']
- def enable_selected(self,requst,queryset):
- queryset.update(is_enabled=True)
- def disable_selected(self,requst,queryset):
- queryset.update(is_enabled=False)
- enable_selected.short_description = "Enable the selected Post"
- disable_selected.short_description = "Disable the selected Post"
- list_display = ['is_enabled']
Add Comment
Please, Sign In to add comment