I am using Django 2.1.3, django-smart-selects 1.5.4 and three simple models for example Client, Billing Account and Order.
What needs to be done is upon Order creation the user should choose a Client (presuming that the count of all registered clients will be a large number) as an autocomplete_field. Upon choosing Client there should be another select with all billing accounts associated for this client.
In Order i have related Client as a ForeignKey and BillingAccount as a ChainedForeignKey to Client using smart-selects as following:
class Order(models.Model):
client = models.ForeignKey(Client, on_delete=models.PROTECT, null=True)
billing_account = ChainedForeignKey(BillingAccount, chained_field="client",
chained_model_field="client",
show_all=False,
auto_choose=True,
on_delete=models.PROTECT,
null=True)
The problem is when the user chooses a given Client, the BillingAccount select wont autofill.
Note:
When Client is not associated in OrderAdmin's autocomplete_fields BillingAccount is filled as it should be with all accounts associated for this Client.
I wrote custom Ajax which is doing the trick for me but my question is:
Is there something that I miss to include or django-smart-selects doesn't work with autocomplete_fields by default?