0
Django 1.7에서는 상위 모델에서 관련 모델 클래스를 가져 오기 위해 간단한 한 줄짜리 탐색기를 빨리 찾을 수 없었습니다.Django : 상위 모델 클래스에서 관련 모델 클래스 가져 오기
이러한 두 모델은 서로 다른 파일에 있으며 종종 다른 주요 순환 문자 (즉 깨진) 가져 오기를 가져옵니다.
# File: classroom_model.py
from django.db import models
class Classroom(models.Model):
class_code = models.IntegerField()
# File: student_model.py
from classroom_model import Classroom
class Student(models.Model):
classroom = models.ForeignKey(Classroom, related_name="student_set")
``여기`
이, 욕망이 만드는 @classmethod를 작성, 예를 들어, 교실에서 학생 모델 클래스에 액세스 할 수 있습니다 : 여기
은 간단한 예제 학생 (예를 들어 classroom.create_student (이름)