Skip to content

Commit

Permalink
BE-tùy chỉnh giao diện admin (Category, Version, Author, Producer, Bo…
Browse files Browse the repository at this point in the history
…ardgameReview)
  • Loading branch information
TTTThanh2812 committed Jul 14, 2023
1 parent 78db74d commit e660113
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Binary file modified Rent_boardgame/boardgame/__pycache__/admin.cpython-310.pyc
Binary file not shown.
31 changes: 21 additions & 10 deletions Rent_boardgame/boardgame/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
from boardgame.models import Category, Version, Author, Producer, Boardgame, BoardgameImages, BoardgameNumbers, BoardgameReviews

class CategoryAdmin(admin.ModelAdmin):
list_display = ['title', 'cid']
search_fields = ['title']
list_display = ['cid', 'title']
list_filter = ['title']
readonly_fields = ['cid']

class VersionAdmin(admin.ModelAdmin):
list_display = ['title', 'vid']
search_fields = ['title']
list_display = ['vid', 'title']
list_filter = ['title']
readonly_fields = ['vid']

class AuthorAdmin(admin.ModelAdmin):
list_display = ['title', 'aid']
search_fields = ['title']
list_display = ['aid', 'title']
list_filter = ['title']
readonly_fields = ['aid']

class ProducerAdmin(admin.ModelAdmin):
list_display = ['title', 'pid']
search_fields = ['title']
list_display = ['pid', 'title']
list_filter = ['title']
readonly_fields = ['pid']

class BoardgameImagesAdmin(admin.TabularInline):
model = BoardgameImages
Expand Down Expand Up @@ -51,8 +55,15 @@ class BoardgameAdmin(admin.ModelAdmin):
readonly_fields = ['bgid', 'boardgame_status', 'in_stock', 'order', 'rental', 'total']

class BoardgameReviewsAdmin(admin.ModelAdmin):
list_display = ['user', 'boardgame', 'review', 'rating']
search_fields = ['boardgame__title', 'rating']
list_display = ['user', 'boardgame', 'display_review', 'rating', 'date']
list_filter = ['boardgame', 'rating']
readonly_fields = ['user', 'boardgame', 'review', 'rating', 'date']
def display_review(self, obj):
MAX_LENGTH = 50
if len(obj.review) > MAX_LENGTH:
return obj.review[:MAX_LENGTH] + '...'
return obj.review
display_review.short_description = 'Review'

admin.site.register(Category, CategoryAdmin)
admin.site.register(Version, VersionAdmin)
Expand Down

0 comments on commit e660113

Please sign in to comment.