I have a Product model that I use to create ProductFormSet. How do I specify the label_suffix to be something other than the default colon? I want it to be blank. Solutions I've seen only seem to apply when initiating a form - here.
ProductFormSet = modelformset_factory(Product, exclude=('abc',))
products = Product.objects.order_by('product_name')
pformset = ProductFormSet(queryset=products)
In Django 1.9+, you can use the form_kwargs
option.
ProductFormSet = modelformset_factory(Product, exclude=('abc',))
products = Product.objects.order_by('product_name')
pformset = ProductFormSet(queryset=products, form_kwargs={'label_suffix': ''})
In earlier Django versions, you could define a ProductForm class that sets the label_suffix
to blank in the __init__
method, and then pass that form class to modelformset_factory
.
class ProductForm(forms.ModelForm):
...
def __init__(self, *args, **kwargs):
super(ProductForm, self).__init__(*args, **kwargs)
self.label_suffix = ''
ProductFormSet = modelformset_factory(Product, form=ProductForm, exclude=('abc',))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With