1. Django Tutorial(Airbnb) - Meta Class
8066 ワード
🌈 Meta Class
🔥 abstract
🔥 verbose_name & verbose_name_plural
🔥 ordering
1. abstract
class AbstractItem(core_models.TimeStampedModel): # 👈 TimeStampedModel 상속 받음
"""AbstractItem Object Definition"""
name = models.CharField(max_length=80)
class Meta:
abstract = True # 👈 Abstract Model로 사용
def __str__(self):
return self.name
class RoomType(AbstractItem): # 👈 AbstractItem 상속 받음
"""Room Type Model Definition"""
pass
class Amenity(AbstractItem): # 👈 AbstractItem 상속 받음
"""Amenity Model Definition"""
pass
class Facility(AbstractItem): # 👈 AbstractItem 상속 받음
"""Facility Model Definition"""
pass
class HouseRule(AbstractItem): # 👈 AbstractItem 상속 받음
"""HouseRule Model Definition"""
pass
2. verbose_name & verbose_name_plural
class RoomType(AbstractItem):
"""Room Type Model Definition"""
class Meta:
verbose_name = "Room Type" # 👈 Room Types로 나타남
class Amenity(AbstractItem):
"""Amenity Model Definition"""
class Meta:
verbose_name_plural = "Amenities" # 👈 Amenities로 나타남
class Facility(AbstractItem):
"""Facility Model Definition"""
class Meta:
verbose_name_plural = "Facilities" # 👈 Facilities로 나타남
class HouseRule(AbstractItem):
"""HouseRule Model Definition"""
class Meta:
verbose_name = "House Rule" # 👈 House Rules로 나타남
3. ordering
class RoomType(AbstractItem):
"""Room Type Model Definition"""
class Meta:
verbose_name = "Room Type"
ordering = [created] # 👈 생성시간 기준으로 정렬(부모 Model에 created 필드가 존재)
class Amenity(AbstractItem):
"""Amenity Model Definition"""
class Meta:
verbose_name_plural = "Amenities"
ordering = [name] # 👈 알파벳 기준으로 정렬(부모 Model에 name 필드가 존재)
Reference
この問題について(1. Django Tutorial(Airbnb) - Meta Class), 我々は、より多くの情報をここで見つけました https://velog.io/@jewon119/Django-기초-Meta-Classテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol