Opened 3 years ago

Closed 3 years ago

#32759 closed New feature (wontfix)

Use dataclasses to represent models

Reported by: adsharma Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Django documentation and current practice are described in this example:

This has a number of limitations:

  • Python's type checkers don't understand models.CharField and models.DateTimeField
  • They do understand python strings and datetime objects
  • There is some activity on typing-sig about teaching them more about lengths and limits

dataclasses introduced in 3.7 are seeing some adoption.

The same example can be represented as:

This is more ergonomic for python programmers trained on dataclasses.

Queries against these dataclasses can be expressed in one of two ways:

  • A method chaining API such as:

  • SQL via ActiveRecord or DataMapper

For this to work as well as current django models, two things need to happen:

  • How to pass additional metadata about database schema? (dataclasses support metadata, perhaps make it more ergonomic?)
  • What to do about indices, views and other db concepts

One school of thought is to use SQL DDL.

Some conversation on this topic here:

Would love to hear more from the django community on the topic.

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: wontfix
Status: newclosed

Thanks for the proposition, however I don't think it needs to be built-in into Django it sounds like a third-party package is the best way to proceed.

By the way, you'll reach a wider audience if you write to the DevelopersMailingList about your ideas, see Requesting features.

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