Skip to content

The AutoModelSelect2Field does not work for new added form when used with admin.StackedInline #32

Closed
@yflau

Description

@yflau

I want to use the AutoModelSelect2Field in django admin within a inline form like this:

forms.py

class ProductChoices(AutoModelSelect2Field):
    queryset = Product.objects
    search_fields = ['name__icontains', ]

class OrderItemAdminForm(forms.ModelForm):
    product = ProductChoices(required=False, label=_("Product"))
    performlist = forms.DateTimeField(required=False, widget=PerformList)
    pricelist = forms.IntegerField(required=False, label=_("Price List"), widget=PriceList)
    class Meta:
        model = OrderItem

admin.py

class OrderItemInline(admin.StackedInline):
    form = OrderItemAdminForm
    model = OrderItem
    extra = 1
    fields = ('product', 'performlist', 'pricelist', 'price', 'quantity', 'receivable', 'received')
    raw_id_fields = ['price',]

it is all ok but when I click the add another inline form, the AutoModelSelect2Field of the new added form does not work, I think I should use jquery live method to bind new add element, but I don't know how to do? Can you give me some hints, thanks

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions