yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.8k stars 467 forks source link

Question: autocomp url #1206

Closed solace closed 3 years ago

solace commented 3 years ago

A possible daft question as I'm getting an error about the reverse for {}_autocomp_{} 404ing. But several things are NQR atm, so I'm just trying to trace through code to understand what's going on a bit better in case my issues are self-inflicted.

In dal_select2_queryset_sequence/fields.py we have:

def as_url(self, form):
        """Return url."""
        url_name = '{}_autocomp_{}'.format(form.__name__, self.field_id)

        forward_fields = {
            forward_tuple[0]
            for field in self.model_choice if len(field) > 2
            for forward_tuple in field[2]
        }
        # a set of the fields to forward.
        # it checks if the 3rd index of the list exists

        self.widget = QuerySetSequenceSelect2(
            url=url_name, forward=forward_fields
        )

        # generate the class to work with multiple gfk
        # (can't work on instance level)
        auto_view = type(
            'Autoview{}{}'.format(form.__name__, self.field_id),
            (Select2QuerySetSequenceAutoView,),
            {'model_choice': self.model_choice}
        )  # send to the view the model and filter list

        return url(
            r'^{}_{}_autocomp$'.format(form.__name__, self.field_id),
            auto_view.as_view(),
            name=url_name
        )

Is it intentional for url_name to be {}_autocomp_{} and the return URL to be {}_{}_autocomp?

solace commented 3 years ago

Yeah, this was a daft question. I misunderstood the assignment in to self.widget as the actual endpoint and not the reverse lookup name. My apologies. Trying to nut out that GFK add link thing in #1205 and my eyes are glazing over.