Setting label_suffix for a Django model formset
<p>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 - <a href="http://stackoverflow.com/questions/23973954/adding-a-label-suffix-to-modelform">here</a>.</p>

<pre><code>ProductFormSet = modelformset_factory(Product, exclude=('abc',))    
products = Product.objects.order_by('product_name')
pformset = ProductFormSet(queryset=products)
</code></pre>

<p>In Django 1.9+, you can use the <a href="https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#passing-custom-parameters-to-formset-forms" rel="nofollow"><code>form_kwargs</code></a> option.</p>

<pre><code>ProductFormSet = modelformset_factory(Product, exclude=('abc',))    
products = Product.objects.order_by('product_name')
pformset = ProductFormSet(queryset=products, form_kwargs={'label_suffix': ''})
</code></pre>

<p>In earlier Django versions, you could define a ProductForm class that sets the <code>label_suffix</code> to blank in the <code>__init__</code> method, and then pass that form class to <code>modelformset_factory</code>.</p>

<pre><code>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',))    
</code></pre>

python django