Skip to content

Commit

Permalink
TabularInline
Browse files Browse the repository at this point in the history
  • Loading branch information
zpskek committed Feb 21, 2021
1 parent 3456be1 commit 23753af
Showing 1 changed file with 8 additions and 80 deletions.
88 changes: 8 additions & 80 deletions rooms/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from . import models as room_models
from photos import models as photo_models


@admin.register(
Expand All @@ -18,91 +19,18 @@ def used_by(self, obj):
return obj.rooms.count()


class PhotoInline(admin.StackedInline):
model = photo_models.Photo


@admin.register(room_models.Room)
class RoomAdmin(admin.ModelAdmin):

""" Room Admin Definition """

list_display = (
"name",
"country",
"city",
"address",
"price",
"guests",
"bedrooms",
"beds",
"bathrooms",
"host",
"room_type",
"count_amenities",
"count_facilities",
)

list_filter = (
"guests",
"bedrooms",
"beds",
"bathrooms",
"host",
"room_type",
"instant_book",
"country",
"city",
)

search_fields = ("^city", "name", "host__username")

fieldsets = (
(
"Basic Info",
{
"fields": (
"name",
"description",
"country",
"city",
"address",
"host",
"price",
"room_type",
),
},
),
(
"Space",
{
"fields": (
"guests",
"bedrooms",
"beds",
"bathrooms",
)
},
),
(
"More about space",
{
"fields": (
"amenities",
"facilities",
"house_rules",
)
},
),
(
"Booking",
{"fields": ("instant_book",)},
),
)

raw_id_fields = ("host",)

filter_horizontal = (
"amenities",
"facilities",
"house_rules",
)
inlines = [
PhotoInline,
]

def count_amenities(self, obj):
return obj.amenities.count()
Expand Down

0 comments on commit 23753af

Please sign in to comment.