๐ฅ abstract
๐ฅ verbose_name & verbose_name_plural
๐ฅ ordering
1. abstract
- Meta Class์ abstract๋ Default๊ฐ "abstract=False"์ด๊ณ , "abstract=True"๋ก ํ ๊ฒฝ์ฐ Abstract Model๋ก ์ฌ์ฉ ๊ฐ๋ฅ ํด์. ์ค์ ์กด์ฌํ๋ DB๊ฐ ์๋ ๋ค๋ฅธ Model์์ ์์ํ์ฌ ์ฌ์ฉํ ๋ชฉ์ ์ผ๋ก ํ
์ด๋ธ์ ๋ง๋ค ๋ ์ฌ์ฉํฉ๋๋ค.
class AbstractItem(core_models.TimeStampedModel):
"""AbstractItem Object Definition"""
name = models.CharField(max_length=80)
class Meta:
abstract = True
def __str__(self):
return self.name
class RoomType(AbstractItem):
"""Room Type Model Definition"""
pass
class Amenity(AbstractItem):
"""Amenity Model Definition"""
pass
class Facility(AbstractItem):
"""Facility Model Definition"""
pass
class HouseRule(AbstractItem):
"""HouseRule Model Definition"""
pass
2. verbose_name & verbose_name_plural
- Admin Panel์ ๋ณด๋ฉด, Django์์ ์์์ ๋ชจ๋ Model ์ด๋ฆ์ "s"๋ฅผ ๋ถ์ฌ์ค ๊ฒ์ ๋ณผ ์ ์์ด์. Django๊ฐ ์์์ ๋ณต์๋ก ํํ์์ผ ์ค๋๋ค.
- ๋ค๋ง, "verbose_name"๊ณผ "verbose_name_plural" ์์ฑ์ ํตํด ์ด๋ฅผ ๋ค๋ฅด๊ฒ ์ง์ ํ ์ ์์ด์!
- verbose_name์ "์ง์ ํ ๊ฐ + s"๋ฅผ ๋ถ์ฌ์ค๋๋ค.
- verbose_name_plural์ "์ง์ ํ ์ด๋ฆ" ๊ทธ๋๋ก ์ฌ์ฉํฉ๋๋ค.
class RoomType(AbstractItem):
"""Room Type Model Definition"""
class Meta:
verbose_name = "Room Type"
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"
3. ordering
- ordering์ Model์ ๋ฐ์ดํฐ(Object)๋ค์ ์ ๋ ฌํ๋๋ฐ ์ฌ์ฉํด์!
- ๐ ordering = [์ ๋ ฌ ๊ธฐ์ค ํ๋๊ฐ]
class RoomType(AbstractItem):
"""Room Type Model Definition"""
class Meta:
verbose_name = "Room Type"
ordering = [created]
class Amenity(AbstractItem):
"""Amenity Model Definition"""
class Meta:
verbose_name_plural = "Amenities"
ordering = [name]