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

get_items option not used if model is defined within widget #63

Open
fabien-michel opened this issue Nov 8, 2024 · 0 comments
Open

Comments

@fabien-michel
Copy link

fabien-michel commented Nov 8, 2024

According to this comment of the HTMXAutoComplete class:

Note: You must either add a `Meta.model` attribute or override
`get_items`. If you do both the defined model is accessible via
`self.Meta.model`, and the `item_value` and `item_label` properties are
accessible as `self._item_value` and `self._item_label` respectively.

It is possible to define both the model and get_items options. In that case it is say to be possible to access given model using self.Meta.model

But the code of the widget doesn't allow it because defining model skip the get_items override part:

if model := opts.get("model", None):
mdl_config = {"model": model}
if item_value := opts.get("item_value", None):
mdl_config["item_value"] = item_value
if item_label := opts.get("item_label", None):
mdl_config["item_label"] = item_label
if lookup := opts.get("lookup", None):
mdl_config["lookup"] = lookup
config["Meta"] = type("Meta", (object,), mdl_config)
else:
config["get_items"] = opts.get("get_items", HTMXAutoComplete.get_items)

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

1 participant