I have a model
class StudentEfficacy(models.Model):
class FatherEducation(models.IntegerChoices):
NoEducation = 0, _("No Education")
PrimaryEducation = 1, _("Primary Education")
SecondaryEducation = 2, _("Secondary Education")
GraduateStudy = 3, _("Graduate Study")
PostGraduateStudy = 4, _("Post Graduate Study")
DoctorOfPhilosophy = 5, _("Doctor of Philosophy")
student_efficacy_id = models.AutoField(primary_key=True)
father_education = models.IntegerField(choices=FatherEducation.choices)
study_time = models.IntegerField("Study Time in mins")
I want to dynamically check if the field has choices
defined.
for example I want to do something like below:
stud = StudentEfficacy.objects.get(pk=1)
if stud.father_education has choices defined:
print(stud.father_education)
elif not stud.study_time has choices defined:
print(stud.study_time)
Actually in the example above I have given fixed models and fields but actual use would be like below:
for model_inst in models_list:
for field in model_field_list[model_inst._meta.verbose_name]
if getattr(model_inst, field) has choices defined:
print("Something")
else:
print("Something else")