Skip to content

Support validation for object fields using form_classes mapping#797

Open
JohananOppongAmoateng wants to merge 4 commits intodjango-commons:mainfrom
JohananOppongAmoateng:object-validation-for-fields
Open

Support validation for object fields using form_classes mapping#797
JohananOppongAmoateng wants to merge 4 commits intodjango-commons:mainfrom
JohananOppongAmoateng:object-validation-for-fields

Conversation

@JohananOppongAmoateng
Copy link
Contributor

This PR adds support for validating component fields that are objects (e.g. company.email) by introducing a form_classes attribute on UnicornView.

Previously, form_class only worked when component properties directly matched form field names (e.g. unicorn:model="email"). However, it did not support nested/object fields such as:

unicorn:model="company.email"

This limitation made it difficult to use ModelForm validation when binding directly to model instances inside a component. Closes #220

@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/django_unicorn
  serializer.py
  src/django_unicorn/components
  unicorn_view.py 611-612, 633, 644-652, 658-659
  tests/components
  test_component.py
  tests/views
  fake_components.py
  tests/views/message
  test_form_classes.py
Project Total  

This report was generated by python-coverage-comment-action

else:
self.errors.update(form_errors)

# ── form_classes path ────────────────────────────────────────────────
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this should be split out to its own function?

Copy link
Member

@adamghill adamghill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some questions here.

@JohananOppongAmoateng
Copy link
Contributor Author

i made the changes

Copy link
Member

@adamghill adamghill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@adamghill
Copy link
Member

@JohananOppongAmoateng Can you rebase this PR so it can be merged cleanly?

@JohananOppongAmoateng JohananOppongAmoateng force-pushed the object-validation-for-fields branch from c16abb2 to fc625b9 Compare February 27, 2026 12:22
@JohananOppongAmoateng
Copy link
Contributor Author

@JohananOppongAmoateng Can you rebase this PR so it can be merged cleanly?

done

@JohananOppongAmoateng
Copy link
Contributor Author

@adamghill i fixed the conflicts you should be able to merge it now

@JohananOppongAmoateng JohananOppongAmoateng force-pushed the object-validation-for-fields branch from b06c28c to f10c03c Compare March 3, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support validation for fields that are objects

2 participants