I try to use django-ajax-selects in a form used in a view (not in the admin). I sucessfully get the autocomplete field working (with lookup), but I don't know how to add the "+" button to add a new record.
My current code looks like:
-- models.py
class Address(models.Model):
partner = models.ForeignKey(Partner, related_name='addresses', verbose_name=_('partner name'))
contact_name = models.CharField(_('contact surname'), max_length=100, blank=True)
contact_first_name = models.CharField(_('contact first name'), max_length=100, blank=True)
class PurchaseOrder(models.Model):
order_number = models.CharField(_('order number'), max_length=100, blank=True,)
supplier = models.ForeignKey(Address, verbose_name=_('supplier'))
-- forms.py
class PurchaseOrderForm(ModelForm):
supplier = AutoCompleteSelectField('address', required=True)
class Meta:
model = PurchaseOrder
fields = ('supplier', 'order_number')
Now, I am supposed to subclass AjaxSelectAdmin or include the autoselect_fields_check_can_add hook in my admin's get_form() AjaxSelectAdmin from the official doc
def get_form(self, request, obj=None, **kwargs):
form = super(AjaxSelectAdmin,self).get_form(request,obj,**kwargs)
autoselect_fields_check_can_add(form,self.model,request.user)
return form
but I have no idea where to add this... Can somebody point me in the right direction?