Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty results when accessing field in chained_field. #346

Open
3 of 7 tasks
YDA93 opened this issue Nov 26, 2022 · 5 comments
Open
3 of 7 tasks

Empty results when accessing field in chained_field. #346

YDA93 opened this issue Nov 26, 2022 · 5 comments

Comments

@YDA93
Copy link

YDA93 commented Nov 26, 2022

Checklist

  • 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 master branch of django-smart-selects.
  • 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_selects app.
  • I have reduced the issue to the simplest possible case.
  • I have included all relevant sections of models.py, forms.py, and views.py with 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()

@YDA93 YDA93 changed the title Inaccurate results when using reverse relationship look up in chained_model_field. Empty results when accessing field in chained_field. Nov 26, 2022
@HoliSimo
Copy link

HoliSimo commented Dec 8, 2022

Have you some results? I'm facing the same problem. I'm forced to add some unwanted foreign key in the model with ChainedForeignKey.

@YDA93
Copy link
Author

YDA93 commented Dec 8, 2022

Hello @HoliSimo

Unfortunately this is not possible in django-smart-select.
And as a result, I stopped using it.

@HoliSimo
Copy link

HoliSimo commented Dec 8, 2022

@YDA93 Did you find something else to handle this use case?

@YDA93
Copy link
Author

YDA93 commented Dec 8, 2022

@HoliSimo
tbh I have not found any other library better than this one.

If you really like the use case, you can use jquery:

  1. Create a view and url to query the objects and make it for admins only.
  2. Add JS file to related admin page.
  3. 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.

@amitv9493
Copy link

I am also having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants