﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37145	ModelFormSet breaks when changing prefix format	Jort Roelofs		"I've been trying to change the way the widget prefixes are formatted to make it work nicely with some JavaScript libraries. Here I ran into the following bug.

{{{class BookForm(forms.ModelForm):}}}
{{{    class Meta:}}}
{{{        ...}}}

{{{    def add_prefix(self, field_name)}}}
{{{        #  Here I use a period as separator instead of a dash.}}}
{{{        return f""{self.prefix}.{field_name}"" if self.prefix else field_name}}}

{{{BookFormSet = modelformset_factory(Book, form=BookForm)}}}


So far so good, this renders the way I expect it to. However, form submission doesn't work, as the check for the primary key is hardcoded to use a dash as separator [https://github.com/django/django/blob/a2348c85fc6c20087935c74cd99340dd4ef2dcdc/django/forms/models.py#L739 here]. When looking for a primary key, it constructs a key with pk_key = ""%s-%s"" % (self.add_prefix(i), self.model._meta.pk.name), but this is inconsistent when the form itself has defined a different way to construct prefixes."	Bug	new	Forms	6.0	Normal		formset		Unreviewed	0	0	0	0	0	0
