-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
48 lines (40 loc) · 1.18 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from django.contrib import admin
from .models import Room, Amenity
@admin.action(description="Set all prices to zero")
def reset_prices(modeladmin, request, rooms):
for room in rooms.all():
room.price = 0
room.save()
# Register your models here.
@admin.register(Room)
class RoomAdmin(admin.ModelAdmin):
actions = (reset_prices,)
list_display = (
"name", "country", "price", "kind", "owner",
"pet_friendly", "rating", "created_at",
)
list_filter = (
"category", "country", "kind", "pet_friendly",
)
search_fields = ("name", "owner__username",)
def total_amenities(self, room):
print(room.amenities.all())
return room.amenities.count()
# model로 옮김
# def average_reviews(self, room):
# tot_reviews = 0
# for review in room.reviews.all():
# tot_reviews += review.rating;
# return tot_reviews / room.reviews.count();
@admin.register(Amenity)
class AmenityAdmin(admin.ModelAdmin):
list_display = (
"name",
"description",
"created_at",
"updated_at",
)
readonly_fields = (
"created_at",
"updated_at",
)