Code

Opened 4 years ago

Closed 2 years ago

Last modified 2 years ago

#13867 closed New feature (wontfix)

Feature request: Comments in Django models saved to database schema

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

Description

Currently there is no way to make comments in the schema via Django. The only way is to alter the tables and add the comments manually in the database.

This feature request presents one possible implementation.

For comments at the table level, use the first line of the Model docstring, truncating it depending on backend limitations.
For comments at the column level, include a comment attribute on the Field declaration.

class Dummy(Model):
    """This comment goes into the schema.
    This and the following won't
    ...
    """
    dummy_name = CharField(max_length=20, comment="All dummies should have names right?")
    ...

In addition, a specific syntax could be used in the docstring to prevent undesired comments in already existing code to be transfered to the database.

Attachments (0)

Change History (8)

comment:1 Changed 4 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I'm assuming this refers to PostgreSQL specific COMMENT extension to SQL. Instead of adding a new comment argument to fields, help_text could be reused. Table comments should probably go into the model's Meta with all the other stuff (like verbose_name). Using a special docstring syntax adds unnecessary complexity and magic.

comment:2 Changed 4 years ago by rjalves

For PostgreSQL yes, for MySQL something like:

 CREATE TABLE `bacteria`.`dummy` (
`dummy_name` VARCHAR ( 20 ) NOT NULL COMMENT 'All dummies should have names right?'
) ENGINE = InnoDB COMMENT = 'This comment goes into the schema.'

I agree with the point about the docstring magic, however for the column comment I think they should be kept separate.
One may want to include a content specific comment in the database and a different message in help_text as user guideline.

comment:3 Changed 4 years ago by rjalves

  • Summary changed from Feature request: docstring and comments in Django models saved to database schema to Feature request: Comments in Django models saved to database schema

comment:4 Changed 4 years ago by brodie

  • Triage Stage changed from Unreviewed to Design decision needed

comment:5 Changed 3 years ago by graham_king

  • Severity set to Normal
  • Type set to New feature

comment:6 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:7 Changed 2 years ago by aaugustin

  • Easy pickings unset
  • Resolution set to wontfix
  • Status changed from new to closed
  • UI/UX unset

I understand the idea, but I'm afraid it doesn't have a good usefulness/noise ratio.

The ORM doesn't aim at providing a Python interface for every feature of the supported database engines. Its goal is "just" to provide an OO API.

Since there's neither a clean API proposal, nor a patch, nor a convincing explanation of the value added by this feature, I'm going to close this ticket.

comment:8 Changed 2 years ago by aaugustin

#18468 is a duplicate with a patch.

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.