Как получить поле модели в Django в шаблонах без ModelForm?
Как получить доступ к полю нашей модели без использования объекта ModelForm в Django?
forms.py
class ChoiceAppointmentForm(forms.Form):
appointment = forms.ModelChoiceField(
queryset=None, widget=forms.RadioSelect)
conference_method = forms.ChoiceField(choices=METHOD_CHOICES)
conference_details = forms.CharField(required=False)
conference_secret_code = forms.CharField(required=False)
def __init__(self, *args, **kwargs):
appointments = kwargs.pop('appointments')
super().__init__(*args, **kwargs)
self.fields['appointment'].queryset = appointments
models.py
class Appointment(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, null = True, on_delete = models.CASCADE)
student = models.ForeignKey(Student, null=True, blank = True, on_delete=models.CASCADE)
is_confirmed = models.BooleanField(default = False)
date = models.DateField(null = True)
choice_appointment.html
<div class="fieldWrapper">
{{ form.appointment.errors }}
{{ form.appointment.date }}
{{ form.appointment }}
</div>
Но он не отображает дату приема. Я могу получить доступ только к объекту назначения, но не к дате, студенту и т.д. Как я могу сделать ?