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

Add support for django-smart-selects #180

Open
ethemce opened this issue Nov 6, 2023 · 3 comments
Open

Add support for django-smart-selects #180

ethemce opened this issue Nov 6, 2023 · 3 comments

Comments

@ethemce
Copy link

ethemce commented Nov 6, 2023

Hello, first of all thanks for this great admin panel.

After some experiments I realized that "django-smart-selects" / "ChainedForeignKey" does not have any effect on the admin panel.
is there any chance to make it compatible with your admin panel?

Thank You.

Example

class Media:
        js = [
            "smart-selects/admin/js/chainedfk.js",
            "smart-selects/admin/js/bindfields.js",
            "smart-selects/admin/js/chainedm2m.js",
        ]
product = ChainedForeignKey(
        Product,
        chained_field="company",
        chained_model_field="company",
        show_all=False,
        auto_choose=True,
        sort=True,
    )
@lukasvinclav lukasvinclav added the enhancement New feature or request label Dec 13, 2023
@mikehowarth-lab
Copy link

Just ran in to the same issue with smart selects - this would be a really worthwhile addition to this fantastic upgrade to the admin console

@mikehowarth-lab
Copy link

mikehowarth-lab commented Dec 23, 2023

Ok spent a little more time looking at this today and managed to hack this together to get this working.

Observations:

  • Jquery Ajax needs to be installed
  • Unfold currently omits the classes and data attributes required for smart select to function.
  • Additional js file needed to add appropriate data attributes

Issues:

  • Data Value is currently hard coded - need to be able to overide this with the departure id so it is pre-selected.

Admin Model Media Class

    class Media:
        js = [
            "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js",
            "smart-selects/admin/js/chainedfk.js",
            "smart-selects/admin/js/bindfields.js",
            "smart-selects/admin/js/chainedm2m.js",
            "js/booking-admin.js"
        ]
// booking-admin.js

const $ = django.jQuery;

$(function() {
    $('select[name="departure').attr('id', 'id_departure');
    $('select[name="departure').attr('data-chainfield', 'trip');
    $('select[name="departure').attr('data-auto-choose', 'true');
    $('select[name="departure').attr('data-url', "/chaining/filter/trips/Departure/trip/bookings/Booking/departure")
    $('select[name="departure"]').attr('data-value', '1');
    $('select[name="departure').attr('data-empty-label', "--------"),
    $('select[name="departure"]').addClass('chained-fk');
});

Need to have more of a think how I can deal with matching the data-value to match the id set in the departure object.

@Biftor
Copy link

Biftor commented Jan 3, 2024

@lukasvinclav
Smart select is something like django-autocomplete-light which i mentioned here (closed),
the problem is just the style, which is not match with unfold
Thank you for your hard working for such great project.

@lukasvinclav lukasvinclav changed the title support for django-smart-selects Add django-smart-selects support Jan 6, 2024
@lukasvinclav lukasvinclav changed the title Add django-smart-selects support Add support for django-smart-selects Jan 6, 2024
@lukasvinclav lukasvinclav added third party and removed enhancement New feature or request labels Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants