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)]
- [Answered ]-Redis for Django-application
- [Answered ]-How to fix "ImportError: No module named …" error
- [Answered ]-Adding permissions when user is saved in Django Rest Framework
- [Answered ]-Upload_to doesn't work when updating user profile?
- [Answered ]-When trying to edit new profile is creating in django
Source:stackexchange.com