Opened 8 years ago

Closed 8 years ago

#27446 closed New feature (duplicate)

Addition of `readonly` option to ModelField to allow database generated fields

Reported by: Ben Cole Owned by: Ben Cole
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: ewjoachim@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ben Cole)

There exist multiple use cases where a database will generate values for a field/column. Most RDBMSes expect that these columns be excluded from from INSERT and UPDATE statements. However they still need to be included in SELECT statements.

Examples include the PostgreSQL serial data type, triggers and functions that generate defaults on INSERT (such as PostgreSQL UUID)

The proposal therefore is to add a readonly option to the base Field class that when True would strip these fields from being compiled to SQL during INSERTs and UPDATEs. This allows for a very simple change that covers all possible write queries that Django may perform (including bulk_*).

There exists a proof of concept https://github.com/novafloss/django-readonly-field

Change History (3)

comment:1 by Ben Cole, 8 years ago

Description: modified (diff)
Owner: changed from nobody to Ben Cole
Status: newassigned

comment:2 by Ben Cole, 8 years ago

Description: modified (diff)

comment:3 by Ben Cole, 8 years ago

Resolution: duplicate
Status: assignedclosed

Is a duplicate of #21454

Note: See TracTickets for help on using tickets.
Back to Top