# ./products/models.py
from django.db import models
class AbstractCar(models.Model):
manufacturer = models.ForeignKey('Manufacturer', on_delete=models.CASCADE)
class Meta:
abstract = True
๋ฉํ ํด๋์ค์ "abstract = True"์ด๋ฉด migrateํ๋๋ผ๋
DB์ ๋ฌผ๋ฆฌํ
์ด๋ธ์ด ์๊ธฐ์ง ์๋๋ค!
์๋๋ฉด ์ถ์ ํ
์ด๋ธ์ด ๋์๊ธฐ ๋๋ฌธ์ด๋ค!
# ./proudction/models.py
from django.db import models
from products.models import AbstractCar
class Manufacturer(models.Model):
pass
class Car(AbstractCar):
pass
- production_car
CREATE TABLE "production_car" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "manufacturer_id" integer NOT NULL REFERENCES "production_manufacturer" ("id") DEFERRABLE INITIALLY DEFERRED)
=> "production_car" ํ ์ด๋ธ์ ์์๋ฐ์ "AbstractCar"์์ ์ ์ ๋ ์ปฌ๋ผ๊ณผ ๊ฐ๋น!- production_manufacturer
CREATE TABLE "production_manufacturer" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT)- ์ฃผ์!!
product_abstractcarํ ์ด๋ธ์ ์์ฑ๋์ง ์์๋ค! ์๋ํ๋ฉด AbstractCar๋ ์ถ์ํด๋์ค๋ก ์ค์ ๋์ด ์๊ธฐ ๋๋ฌธ์ด๋ค!