Tuesday, April 2, 2019

BaseModelFormSet > _construct_form

Hello,

In function _construct_form variable "pk_key" is generated as:
 pk_key = "%s-%s" % (self.add_prefix (i), self.model._meta.pk.name) "

So pk_key is not flexible. Because if I overwrite function "add_prefix" from class "forms.ModelForm", I get error "MultiValueDictKeyError".

My add_prefix function:
def add_prefix(self, field_name):
      return '%s_%s' % (self.prefix, field_name) if self.prefix else field_name


I see a possibility to solve that for now. Overwrite function _construct_form.

Other options?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/92616dd1-1e04-43f6-9e91-edfc56dfe5bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment