#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@…, James Pic | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 (5)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → 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 by , 11 years ago
Cc: | added |
---|
comment:4 by , 9 years ago
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.
How can the object_id field be validated without the knowledge of its GFK's content_type field ?
I'd like to re-open this: some apps have been providing working widgets for GFK for years now, so there's got to be a way.
comment:5 by , 9 years ago
Cc: | added |
---|
Django doesn't have composite fields (yet!). There's a GSOC project (https://github.com/koniiiik/django) to do this, so when it's done it probably will have support for virtual fields on ModelForms.