Code

Opened 3 years ago

Closed 3 years ago

Last modified 11 months 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

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.

Attachments (0)

Change History (3)

comment:1 Changed 3 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 (https://github.com/koniiiik/django) to do this, so when it's done it probably will have support for virtual fields on ModelForms.

comment:2 Changed 3 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 11 months ago by danols

  • Cc ognajd@… added

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.