Opened 5 years ago

Closed 4 years ago

Last modified 2 years ago

#16286 closed New feature (invalid)

Models virtual fields and ModelForms

Reported by: loic84 Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: ognajd@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Problem: ModelForms do not expose models virtual fields.

In case of models composite fields that are managed by a single virtual field it would be useful to be able to supply a form field in ModelForms.

Currently the only virtual field in Django is GenericForeignKey and it doesn't need this feature because each local field it relies on is responsible for its own data. However it would be a great addition for 3rd parties composite fields where the virtual field would need to supply a form field, process the submitted value and then populate local fields for final storage.

Change History (3)

comment:1 Changed 5 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Django doesn't have composite fields (yet!). There's a GSOC project ( to do this, so when it's done it probably will have support for virtual fields on ModelForms.

comment:2 Changed 4 years ago by ptone

  • Resolution set to invalid
  • Status changed from new to closed

There is no practical way to do this in a general purpose way in Django - no way for Django to know which widget to use. This is a case where the solution is to subclass ModelForm and add the form field and behavior you expect for your custom model implementation.

RE the other comment, I believe the OP was not talking about composite PK, but more the use of get/set methods exposed as a property on a model.

comment:3 Changed 2 years ago by danols

  • Cc ognajd@… added
Note: See TracTickets for help on using tickets.
Back to Top