django-autocomplete-light icon indicating copy to clipboard operation
django-autocomplete-light copied to clipboard

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

Open lsmith77 opened this issue 1 year ago • 2 comments

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.

lsmith77 avatar Dec 20 '23 14:12 lsmith77

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

jpic avatar Jan 09 '24 19:01 jpic

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.

lsmith77 avatar Jan 10 '24 08:01 lsmith77