Skip to content

Commit

Permalink
Merge pull request #36 from arpithpm/add-admin-filters-for-models
Browse files Browse the repository at this point in the history
Add admin filters for models.py
  • Loading branch information
arpithpm authored Apr 26, 2023
2 parents a378111 + 4c25061 commit 6dd82c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 36 additions & 5 deletions promptbook/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
from django.contrib import admin
from .models import Category, Prompt, Label, PromptLabel
from .models import Category, Prompt, Label, PromptLabel, Profile
from reversion.admin import VersionAdmin

# Register your models here.
@admin.register(Category)
class YourModelAdmin(VersionAdmin):
pass

admin.site.register([Prompt, Label, PromptLabel])


class ProfileAdmin(admin.ModelAdmin):
list_display = ('user', 'avatar')


class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'created_at', 'modified_at', 'help_text')
search_fields = ('name',)
list_filter = ('created_at', 'modified_at')


class PromptAdmin(admin.ModelAdmin):
list_display = ('text', 'category', 'created_at', 'modified_at', 'owner', 'is_public', 'text_hash')
search_fields = ('text', 'owner__username')
list_filter = ('category', 'created_at', 'modified_at', 'owner', 'is_public')


class LabelAdmin(admin.ModelAdmin):
list_display = ('name', 'created_at', 'modified_at')
search_fields = ('name',)
list_filter = ('created_at', 'modified_at')


class PromptLabelAdmin(admin.ModelAdmin):
list_display = ('label', 'prompt')
search_fields = ('label__name', 'prompt__text')
list_filter = ('label', 'prompt')


admin.site.register(Profile, ProfileAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Prompt, PromptAdmin)
admin.site.register(Label, LabelAdmin)
admin.site.register(PromptLabel, PromptLabelAdmin)
2 changes: 1 addition & 1 deletion promptbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Category(models.Model):
def __str__(self):
return self.name

@reversion.register()

class Prompt(models.Model):
text = models.TextField()
category = models.ForeignKey(Category, on_delete=models.DO_NOTHING)
Expand Down

0 comments on commit 6dd82c2

Please sign in to comment.