so the goal here is to let the customer choose the class date first, and then they can select the class_ID according to the class date. However, they should be able to choose only the classes which are active (active=True) and matches their age group.
So originally I did this by setting the queryset in forms.py
def __init__(self, *args, **kwargs):
super(Enrollment_form, self).__init__(*args, **kwargs)
customer = Customer.objects.get(phone_number=self.initial['customer'])
if customer.age_group not in ['1','2']:
age_group = 'adult'
else:
age_group = customer.age_group
self.fields['class_ID'].queryset = Class_Catalogue.objects.filter(active=True, class_age_group=age_group) | Class_Catalogue.objects.filter(active=True, class_age_group='all')
After using django-smart-selects, I have tried 2 methods.
setting limit_choices_to in models.py in the chainedforeignkey field
hi, I am working with the chainedforeignkey field for my website, however I am unable to define the queryset for the chainedforeignkey to query.
Models.py
so the goal here is to let the customer choose the class date first, and then they can select the class_ID according to the class date. However, they should be able to choose only the classes which are active (active=True) and matches their age group.
So originally I did this by setting the queryset in forms.py
After using django-smart-selects, I have tried 2 methods.
But none of the method works and now I am stuck. Thanks :)