Opened 14 years ago

Closed 12 years ago

Last modified 12 years ago

#13867 closed New feature (wontfix)

Feature request: Comments in Django models saved to database schema

Reported by: Renato Alves 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.

Change History (8)

comment:1 by Łukasz Rekucki, 14 years ago

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 by Renato Alves, 14 years ago

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 by Renato Alves, 14 years ago

Summary: Feature request: docstring and comments in Django models saved to database schemaFeature request: Comments in Django models saved to database schema

comment:4 by Brodie Rao, 13 years ago

Triage Stage: UnreviewedDesign decision needed

comment:5 by Graham King, 13 years ago

Severity: Normal
Type: New feature

comment:6 by Jacob, 12 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:7 by Aymeric Augustin, 12 years ago

Easy pickings: unset
Resolution: wontfix
Status: newclosed
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 by Aymeric Augustin, 12 years ago

#18468 is a duplicate with a patch.

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