I have a django web site which uses django-smart-selects. In one of my models (for a coin which the user can add to a collection), the chained foreign keys are several levels deep:
class CollectionMember(models.Model):
country = models.ForeignKey(
Country, blank=True, null=True, on_delete=models.SET_NULL
)
coin_type = ChainedForeignKey(
CoinType,
chained_field="country",
chained_model_field="country",
show_all=False,
auto_choose=True,
blank=True,
null=True,
on_delete=models.SET_NULL,
)
coin = ChainedForeignKey(
CoinInfo,
chained_field="coin_type",
chained_model_field="coin_type",
show_all=False,
auto_choose=True,
blank=True,
null=True,
on_delete=models.SET_NULL,
)
mint = ChainedForeignKey(
CoinMint,
chained_field="coin",
chained_model_field="coin",
show_all=False,
auto_choose=True,
blank=True,
null=True,
on_delete=models.SET_NULL,
)
When you initially enter the data, the chained selects work wonderfully (meaning that the general questions around "has it all been set up properly" can be answered in the positive).
But, when you then open the entry for edit - using the same form, only having the record added to it as "form instance", the AJAX sort of "jumps a bit" and loses the last two values. In other words, the record has country / coin_type / coin / mint and these initially all display for a second, then the selections on "coin" and "mint" get un-selected.
There is a thread on the project site about this happening which is about 3 years old, but the resolution to it was an upgrade to Django version > 3, and I am running 3.2.15 so it looks like a new problem and not the one fixed at that time.
Any ideas about what I can do?
I followed the installation instructions and expected it to work for "add' and for "edit", but it only works when adding a new record.