-
Notifications
You must be signed in to change notification settings - Fork 467
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
Unable to display data from a model in another app #1196
Comments
Is your problem with the widget or it is with displaying data from another app? I suspect the widget is the problem. Please check that you have loaded the relevant media. Also, you need to specify which frontend you are using. DAL has some incompatibilities with Materialize. Lastly, the information you have provided is not sufficient for anyone to reproduce or understand your issue. |
If the information provided is insufficient to understand what I have done (the extracts I provided are similar to those shown in the DAL tutorial), please let me know what is missing. I am working with the Django admin, with Django Suit as the "skin". The
Some additional info is the loading sequence of files at startup:
I agree it it seems to be widget that is not working as expected (I thought it was working before) - but how would I go about finding what is causing it to fail? |
I tried testing this in a separate project (in case it was a issue with, for example Django Suit) - but there are no problems with that - see https://github.com/gamesbook/django-suit (autocomplete used on the Cities form). However, on checking the developer console for my project, it seems there is an issue with jQuery. Which version should be in use? |
I am not sure, which version of JQuery are you using. I believe the latest version should work fine. I am guessing what you to question is how to ensure that JQuery is included in the admin side of Django for autocomplete light to work. In case there is no implicit way - Which I am sure there is. You can override this templatehttps://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base.html if you know how to . Then include the JQuery there in. |
I have tried installing the latest jQuery; it gets loaded before autocomplete:
However, select itself now throws a read property error: The |
Are you using DAL 3.8.1 ? @danielmorell isn't jQuery part of the built bundle now ? |
I am using 3.8.1 for the test (referred to as "separate project" above) and in the project that is currently failing. Although the actual project is obviously bigger and more complex I am trying to understand what the differences are that could be causing this. |
@gamesbook can we have template and view code too please ? for both cases (where it work and where it doesnt) |
I am not allowed to post the full template code, but can post the header section. The working case is at https://github.com/gamesbook/django-suit - see https://github.com/gamesbook/django-suit/blob/v2/demo/demo/views.py (but there is no template change as such). I don't store the autocomplete processing code in
The base template contains:
There is no other custom template being used; rendering happens through the normal built-in admin templates. |
I don't see the form rendering code, nor the view that's supposed to render the form in its initial state. But maybe Did you try without your jquery script tag at all ? I don't see it in the demo, maybe django-suit already loads its own. |
The code for the form is this:
There is no specific view code to render the form as that is handled by Django admin. I have tried changing the load order for If I do not use jQuery, I now get the error shown in my 3rd message of this thread. |
Update: I tried reverting to an earlier version of DAL - 3.4.1 - and that works as expected. Manually adding in the jQuery library is not needed. The README says: But perhaps the DAL version can be bumped up to show the most recent that will still work? |
Sorry for the late response. @jpic we are still using jQuery supplied by Django. So on pages where jQuery is not loaded by Django by default it will need to be included. The reason is that if a developer wants to replace the default jQuery with a specific version, or Django provides a copy to the view, we don't want to duplicate what we are loading. It also complicates using it with Select2. If Select2 is instantiated as an object method on one instance of jQuery and our Select2 function uses another instance of jQuery, it will fail. @gamesbook the first error you encountered was caused by not having jQuery loaded in the browser for the view. I believe you discovered this already. The second error (where we ironically discover What is the More details about the causeIn the following code where we invoke django-autocomplete-light/src/dal/static/autocomplete_light/autocomplete_light.js Lines 105 to 112 in d498fec
We are passing in I believe the root cause is this... @jpic The django-autocomplete-light/src/dal/static/autocomplete_light/autocomplete_light.js Line 126 in d498fec
This also might require that we only load languages once per autocomplete handling function. I will have to think about the repercussions of this a little more. I don't think it will change the API for developers, but may change how initializations are handled and tracked internally. Also, the language files are Select2 specific and should probably be moved from |
Yes, you may keep the README updated for others, but our policy is to support the latest versions because tdd makes it easy to update confidently @danielmorell Other solutions could be: a) Perhaps we could add a jQuery with noconflict to the bundle ? b) maybe not using form.media at all ? then we'd just be answering to people who forget to add the static scripts in their templates but that's a lot easier to see coming at a thousand miles distance. c) choices "similar to select2 but without jquery"
Probably worth renaming that argument for posterity ? |
Yes, you may keep the README updated for others, but our policy is to support the latest versions because tdd makes it easy to update confidently Not sure who "you" is? A project team member will need to do this. |
Someone who has a live and running version with 1.11 can clicking the edit link on the file, but it will need a project member to merge for sure. We can't ask our project members to manually verify 1.11, we've already got plenty on our hands, hopefully situation should improve once we offer the webcomponent but that's planned for the following months so we're trying to hang on until then. |
@gamesbook Could you try removing the "research:" and "core:" prefixes of your urls ? Could you paste the output HTML ? Including the data- attributes particularly. It doesn't look like namespaces are properly configured, it would be nice to know that it also doesn't work without namespaces. While I use namespaces in Django urls myself, I'm not sure why they are so tricky and require to "repeat yourlself". For a namespace to work you need to:
Otherwise I don't think it will work, unless the situation has much improved since last time I checked. I wouldn't know because I don't manage URLs myself anymore, I let CRUDLFA+ do the job and it does setup nice namespaces for me by itself. Thank you for your patience |
Given that DAL "just worked" when I switched to an earlier version, I am unsure why you suggest all these changes? |
I think that there is a mistake in your URL configuration. |
Why would an incorrect URL mean that an earlier version works? What has changed to cause this? |
Django 1.11
DAL works well when dislalying data from a model within the same app; however, I cannot get it work when used in another app in the same project.
urls.py
(research app):Browser:
http://127.0.0.1:8000/research/domain-auto?q=KN00
Results:
In main
urls.py
:In another app...
Form definition:
However the widget is not rendered as a normal autocomplete widget and no data is showing for it
I have also tried:
in the form definition, but this has the same outcome.
The text was updated successfully, but these errors were encountered: