-
Notifications
You must be signed in to change notification settings - Fork 8
[WIP] Feat: Search for model instances #49
base: main
Are you sure you want to change the base?
Conversation
/autocomplete.py
for more information, see https://pre-commit.ci
khanxmetu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Simplify by removing the
remote_model,source_fieldandto_fieldvariables. - Only
term,app_label,model_nameare required in the request. app_labelandmodel_nameare used to retrieve the specified model's ModelAdmin for querying.- The queryset is then serialized into a list of dictionaries with primary key and str representation of the object
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
khanxmetu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to create a custom AdminSite to override and add new methods to it while retaining a similar structure so it could be merged into django easily.
…rderedObjectListWarning with pagination
for more information, see https://pre-commit.ci
| if not qs.query.order_by: | ||
| qs = qs.order_by('pk') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is added to avoid UnorderedObjectListWarning. I'd like to see deterministic results on each search but I'm not quite sure if we should force the ordering ourselves. For reference, select2's autocomplete view doesn't take care of this.
|
@khanxmetu Thanks, this looks interesting. Did you try using the existing view? Is anything here different from the one used by autocomplete_fields? I was kind of hoping we could use the existing view directly somehow. |
|
The existing autocomplete view does not work here as it is. Autocomplete requires 4 request parameters: In our case we require only 3 parameters: Therefore a request like: Would fail since autocomplete view would expect a |
|
Ah I understand, so to merge this it would be required to change the signature and code here a bit. That's probably acceptable. Before really looking to merge this I would want to have the frontend working also, even if it's ugly. I'd also suggest setting up pre-commit locally so it passes in CI. |
object Note that DefaultAdminSite is a LazyObject so this seems like a correct way to do it
b45f4e8 to
23b1b8d
Compare
|
For the frontend, I think its okay to use select2 library that the If we could agree on using select2 for instance search then I may also convince you to use it for model search too for this feature as well as go to change list feature as select2 allows navigating and selecting rows with keys without any additional javascript. |
|
@knyghty requesting your early feedback on select2-based frontend. I can follow up with tests afterwards, if this looks in the right direction. |
|
@khanxmetu select2 is okay I think as long as it'll work with what's already in the admin. In the future I think it makes sense to move away from select2 for both this and autocomplete_fields but it's probably the right way to go for now. |
Hi, I have a little suggestion here @khanxmetu : can we let
|
|
@CodemanRichard Although this view was written with reference to Only two trivial methods |
|
@khanxmetu Yes you're right, the core logic is different, then let's just don't use inheritance here. Thanks for your explanation. |
…n containers; make views folder a package
|
@knyghty I believe this PR is ready for another look. I had to make some changes unrelated to this PR specifically to get the urls and tests working. I think this is quite a big changeset, if you want me to split it into multiple PRs, let me know. |
Pull Request Test Coverage Report for Build 14251904300Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
@khanxmetu can you give me some instructions how to get this branch working? I'm using my package https://github.com/knyghty/django-admin-demo and I can't seem to get the settings right to test manually. If I remove |
|
@knyghty In Here's how my Alternatively, I suggest you to try running selenium tests since they have their own |
|
Sorry, it's a bit embarrassing how long it took me to get to this. Now that we're in the context of GSoC (though also aware we've not really started yet)... It works! That's amazing. We could merge this here, once it's ready. But what I'm considering is if there's part of this that we could merge into Django first? I'm not sure what that would be, exactly, perhaps the changes to the I also wonder about the future viability of jQuery. We're already trying to reduce its usage in the admin. However I don't know if there's a good select2 alternative out there. It would be a shame to add more jQuery into Django I think, but also not the end of the world. |
AutocompleteJsonViewAdminSite, and override default admin site, restructure app configresolves Add a shortcut to jump to any model instance #5