1. Django Tutorial(Airbnb) - Abstract Model
7717 ワード
🌈 Abstract Model
🔥 抽象モデルとは?
🔥 抽象モデル継承の取得
🔥 Django Countryライブラリ
1.抽象モデルとは?
1) core/models.py
from django.db import models
# Create your models here.
class TimeStampedModel(models.Model): # 👈 다른 모델에서 사용되어질 Abstract Model입니다:)
"""Time Stamped Definition"""
created = models.DateField(auto_now_add=True) # 👈 다른 모델에서 공통적으로 사용할 필드
updated = models.DateField(auto_now=True) # 👈 다른 모델에서 공통적으로 사용할 필드
class Meta:
abstract = True # 👈 Abstract Model로 사용하기 위해서는 abstract=True를 지정해줘야해요!
2.抽象モデル継承の取得
1) rooms/models.py
from django.db import models
from core import models as core_models
# Create your models here.
class Room(core_models.TimeStampedModel): # 👈 TimeStampedModel의 필드를 상속 받아 사용
"""Room Model Definifion"""
pass
3.Django Countryライブラリ
1)Django国とは?
2) settings.py
# Application definition
DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
PROJECT_APPS = [
"users.apps.UsersConfig",
"rooms.apps.RoomsConfig",
"reviews.apps.ReviewsConfig",
"reservations.apps.ReservationsConfig",
"lists.apps.ListsConfig",
"core.apps.CoreConfig",
"conversations.apps.ConversationsConfig",
]
THIRD_PARTY_APPS = [
"django_countries", # 👈 Django Country App 등록
]
INSTALLED_APPS = DJANGO_APPS + PROJECT_APPS + THIRD_PARTY_APPS
3) rooms/models.py
from django.db import models
from django_countries.fields import CountryField # 👈 Django Country 가져오기
from core import models as core_models
# Create your models here.
class Room(core_models.TimeStampedModel):
"""Room Model Definifion"""
name = models.CharField(max_length=140)
description = models.TextField()
country = CountryField() # 👈 끝.
Reference
この問題について(1. Django Tutorial(Airbnb) - Abstract Model), 我々は、より多くの情報をここで見つけました https://velog.io/@jewon119/Django-기초-Abstract-Modelテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol