django-smart-selects
django-smart-selects copied to clipboard
Empty results when accessing field in `chained_field`.
Checklist
- [X] This issue is not about installing previous versions of django-smart-selects older than 1.2.8. I understand that previous versions are insecure and will not receive any support whatsoever.
- [ ] I have verified that that issue exists against the
masterbranch of django-smart-selects. - [X] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [ ] I have debugged the issue to the
smart_selectsapp. - [X] I have reduced the issue to the simplest possible case.
- [ ] I have included all relevant sections of
models.py,forms.py, andviews.pywith problems. - [ ] I have used GitHub Flavored Markdown to style all of my posted code.
Steps to reproduce
class Service(models.Model):
...
class ServiceOption(models.Model):
service = models.ForeignKey(
Service,
on_delete=models.PROTECT,
related_name="options",
verbose_name=_("Service"),
)
class PartnerService(models.Model):
service = models.ForeignKey(
Service,
on_delete=models.PROTECT,
related_name="partners",
verbose_name=_("Service"),
)
class PartnerServiceOption(models.Model):
service = models.ForeignKey(
PartnerService,
on_delete=models.PROTECT,
related_name="options",
verbose_name=_("Service"),
)
option = ChainedForeignKey(
ServiceOption,
chained_field="service__service",
chained_model_field="service",
auto_choose=True,
on_delete=models.PROTECT,
related_name="partners",
verbose_name=_("Service Option"),
)
Actual behavior
I end up with no results
Expected behavior
Should return selected_service.options.all()
Have you some results? I'm facing the same problem. I'm forced to add some unwanted foreign key in the model with ChainedForeignKey.
Hello @HoliSimo
Unfortunately this is not possible in django-smart-select. And as a result, I stopped using it.
@YDA93 Did you find something else to handle this use case?
@HoliSimo tbh I have not found any other library better than this one.
If you really like the use case, you can use jquery:
- Create a view and url to query the objects and make it for admins only.
- Add JS file to related admin page.
- Add two functions one to update options and one to make Ajax request.
I know this might sounds a lot but its not and all the code can be re-used on other pages.
I am also having the same issue.