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

Forward id for a models.ForeignKey("self") #1346

Open
lsmith77 opened this issue Dec 20, 2023 · 2 comments
Open

Forward id for a models.ForeignKey("self") #1346

lsmith77 opened this issue Dec 20, 2023 · 2 comments

Comments

@lsmith77
Copy link

I want to prevent being abel to select the model itself.

But forward.Field("id", "ignore_id"), doesn't work since there is no "id" form field. What is the easiest way to handle this?

I guess I could write a javascript handler to look at the URL, but maybe there is a simpler way to achieve this.

@jpic
Copy link
Member

jpic commented Jan 9, 2024

Can you add the id in a GET param of the autocomplete url and then filter it out?

@lsmith77
Copy link
Author

Here is the "solution" I found by inspecting the generated HTML but it feels very hacky:

                forward=(
                    # Hacky workaround for https://github.com/yourlabs/django-autocomplete-light/issues/1346
                    forward.Field("children-__prefix__-parent", "ignore_id"),
                    forward.Field("language"),
                ),

It seems like children-__prefix__-parent contains the ID I need.

I have not figured out how I can dynamically add a GET parameter.

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

2 participants