[Answered ]-Django field display in template by group

1👍

Don’t iterate through self.fields in your get_group methods, but through self directly. self.fields contains the raw field instances: for display, Django creates BoundField instances which wrap those fields, and which you access directly via self['fieldname'].

1👍

For representing form fields in template Django uses BoundField. BoundField used to display HTML or access attributes for a single field of a Form instance. So in your case, you should wrap grouped fields with BoundField, like this:

def get_group_a(self):
    return [BoundField(self, field, name) for name, field in self.fields.items() if isinstance(field, GroupAField)]

def get_group_b(self):
    return [BoundField(self, field, name) for name, field in self.fields.items() if isinstance(field, GroupbField)]

Leave a comment