0
모델 '약속'이 있습니다. 그 클래스 환자는 내장 된 사용자 모델과 연관되어 있습니다. 나는 그 클래스에 대한 모델 형식을 만들었습니다. 동일한 폼 내에서 다른 클래스 (필드 환자의 사용자)의 개체를 인스턴스화 할 수 있습니까? 양식의 사용자 모델 필드에 액세스 할 수 없습니다. 어떻게 할 수 있습니까? 나는 다음과 같이이 모델에 대한 ModelForm을 만든하위 클래스의 ModelForm에서 상위 클래스 개체 만들기
class Appointment(models.Model):
doctor = models.ForeignKey(Doctor)
clinic = models.ForeignKey(Clinic, null=True, blank=True)
hospital = models.ForeignKey(Hospital, null=True, blank=True)
day = models.DateField()
time = models.TimeField()
patient = models.ForeignKey(User)
:
class HospitalCreateAppointmentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(HospitalCreateAppointmentForm, self).__init__(*args, **kwargs)
for field in iter(self.fields):
self.fields[field].widget.attrs.update({
'class': 'form-control'
})
class Meta:
model = Appointment
fields = ['doctor','hospital','day','time','patient']
widgets = {
'day': forms.SelectDateWidget(),
}
약속을 예약 할 때마다, 나는 것을 원하는이 그것을 인스턴스화 뒤에 추론 환자가 사이트에서 사용자가되어 자신의 약속 상태를 확인할 수 있습니다. – blueChair