AndrewIngram / django-extra-views

Django's class-based generic views are awesome, let's have more of them.
MIT License
1.38k stars 172 forks source link

Edit 'error_messages' in 'CreateWithInLinesView' #241

Closed eudaldt closed 2 years ago

eudaldt commented 2 years ago

Is there a way to edit a field message error using CreateWithInLinesView? In a ModelForm I used to do this:

class FormulariCaptura(ModelForm):
    name = forms.CharField(error_messages={'unique': 'There's an entry withe the same name'}
    class Meta:
        model = CaptureVersion
        fields = ("name", "int_reference_number", "capture_version_id_provider", "associated_register", "start_date", 
        "end_date", "target_size", "probe_size", "sections", "responsibles",)
sdolemelipone commented 2 years ago

Yes, you can set the form_class attribute on the InlineFormsetFactory instance, e.g.:

from extra_views import CreateWithInLinesView, InlineFormsetFactory

class MyView(CreateWithInLinesView):
    ...
    model = Capture  # I guess
    inlines = [CaptureVersionInline]

class CaptureVersionInline(InlineFormsetFactory):
    model = CaptureVersion
    form_class = FormulariCaptura
eudaldt commented 2 years ago

Perfect, thanks!