#4 ROOM APP - WONILLISM/Clone_airbnb GitHub Wiki

created by wopark

created by mki

#4.0 TimeStampedModel (07:16)

공통 부분을 core로...

AbstarctModel

abstarct = true

class Meta:

#4.1 Room Model part One (12:24)

Django countries

https://github.com/SmileyChris/django-countries

pipenv install django-countries
from django.db import models
from django_countries.fields import CountryField
from core import models as core_models
from users import models as user_models

class AbstractItem(core_models.TimeStampModel):

    """Abstract Item"""

    name = models.CharField(max_length=80)

    class Meta:
        abstract = True

    def __str__(self):
        return self.name

class RoomType(AbstractItem):

    """RoomType Model Definition"""

    class Meta:
        verbose_name = "Room Type"
        ordering = ["created"]
        # ordering = ["name"]

class Amenity(AbstractItem):

    """Amenity Model Definition"""

    class Meta:
        verbose_name_plural = "Amenities"

class Facility(AbstractItem):

    """Facility Model Definition"""

    class Meta:
        verbose_name_plural = "Facilities"

class HouseRule(AbstractItem):

    """HouseRule Model Definition"""

    class Meta:
        verbose_name = "House Rule"

class Photo(core_models.TimeStampModel):

    """Photo Model Definition"""

    caption = models.CharField(max_length=80)
    file = models.ImageField()
    room = models.ForeignKey("Room", on_delete=models.CASCADE)

    def __str__(self):
        return self.caption

class Room(core_models.TimeStampModel):

    """Room Model Definition"""

    name = models.CharField(max_length=140, null=True)
    description = models.TextField(null=True)
    country = CountryField(null=True)
    city = models.CharField(max_length=80, null=True)
    price = models.IntegerField(null=True)
    guests = models.IntegerField(null=True)
    address = models.CharField(max_length=140, null=True)
    beds = models.IntegerField(null=True)
    bedrooms = models.IntegerField(null=True)
    baths = models.IntegerField(null=True)
    check_in = models.TimeField(null=True)
    check_out = models.TimeField(null=True)
    instant_book = models.BooleanField(default=False)
    host = models.ForeignKey("users.User", on_delete=models.CASCADE, default="")
    room_type = models.ForeignKey("RoomType", on_delete=models.SET_NULL, null=True)
    amenities = models.ManyToManyField("Amenity", blank=True)
    facilities = models.ManyToManyField("Facility", blank=True)
    house_rules = models.ManyToManyField("HouseRule", blank=True)

    def __str__(self):
        return self.name

ForeignKey!

DateTimeField

auto_now_add

auto_now

user와 연결이 되었다.

#4.2 Foreing Keys like a Boss (06:24)

ForeignKey는 다른 것과 연결을 해준다.

Many to One

User Host

#4.3 ManyToMany like a Boss (11:31)

model

many to many

ManyToManyField

#4.4 on_delete, Amenity, Facility, HouseRule Models (11:31)

User

on_delete

s있는 것 없는것.

#4.5 Meta Class and Photos Model (09:43)

verbose_name_plural

Meta Class