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

Request for dedicated wiki page / tutorial on how to include DjangoQL autocompletion on webpage #96

Open
simplylu opened this issue Aug 15, 2022 · 3 comments

Comments

@simplylu
Copy link

Hi, thanks for this awesome package.
Whilst all is working great for now, I do not have a working autocompletion in my frontend.
When copying your example, all is working great. But as soon as I'm trying to adapt to my model, it fails miserably.
Thus, I now left it as nice to have on my pile of features.

But I'd like to request a tutorial on how to build this example with detailed explanation on the different blocks of code, especially in models.py / views.py, since they are not explained right now. This makes it kinda difficult (at least for me) to adapt to other models.
At least an explanation would be really nice.

Thx!

@stebunovd
Copy link
Member

Hi there!

The DjangoQL completion widget can be installed separately as an NPM package. The Python DjangoQL distribution already includes a compiled version of djangoql-completion, but if you'd like to use it in your custom-built frontend, it could be much more convenient to use the NPM package.

The djangoql-completion repo includes a basic readme that describes the completion widget public API. Of course, this is not a complete tutorial, but maybe it could be helpful - please check it out.

@simplylu
Copy link
Author

Hi, thanks for the quick reply.
I know the page and I tried to follow it, but I'm not using JS on the backend site, unfortunately.
I'm also a little confused, since the example from your repo works without the npm package, doesn't it?
And if so, how can I do so as well, but for a different model?

I'll again try it tomorrow, but I don't think I'll be successful, since I'm struggling with this since days.

@stebunovd
Copy link
Member

Sorry, it seems that I misunderstood your original question. If you only need to use the autocompletion widget for another model, you probably don't have to deal with the npm package or customize the widget.

... the example from your repo works without the npm package, doesn't it?

The Python DjangoQL distribution is already shipped with the compiled version of the npm package for your convenience, and this is good enough for simple use cases. However, if you have a custom-built frontend based on Webpack or a similar JS bundler, you may want to switch to the npm widget distribution.

Back to your original question, the Using completion widget outside of Django admin section in the readme provides an example based on the User model. The template in this example doesn't have any model-specific code, and it should work out of the box with any other model. No changes in your models.py are required either; everything is in the views.py. If you'd like to use it for another model, replace Userin the views.py with your model and (optionally) provide a custom search schema for your model.

Search schema defines limitations and additional capabilities: which fields and models can be used in the search, should there be any field value suggestions, custom search fields, or a custom search logic. Suppose you don't need to customize the search schema just yet. In that case, you can omit the custom search schema definition entirely (UserQLSchema in the readme's example) and just use the base built-in DjangoQLSchema instead of it, which is universal and compatible with any model.

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