DESCRIPTION in a Django model

I want to know the columns in a table. Is there a django?

+6
source share
4 answers

You can use model._meta.get_all_field_names () to get a list of all the fields in the model class.

+9
source

You can use ./manage.py sqlall <app name> to print the SQL used to create the table for this application. To participate in the project project survey:

 tutorial% ./manage.py sqlall polls BEGIN; CREATE TABLE "polls_poll" ( "id" integer NOT NULL PRIMARY KEY, "question" varchar(200) NOT NULL, "pub_date" datetime NOT NULL ) ; CREATE TABLE "polls_choice" ( "id" integer NOT NULL PRIMARY KEY, "poll_id" integer NOT NULL REFERENCES "polls_poll" ("id"), "choice" varchar(200) NOT NULL, "votes" integer NOT NULL ) ; CREATE INDEX "polls_choice_763e883" ON "polls_choice" ("poll_id"); COMMIT; 

What you may find useful.

+6
source

The easiest way I've found is to use print Class.__doc__ , for example:

 >>> from network.models import Network >>> print Network.__doc__ Network(id, network, name, location) 
+3
source

You can also view model fields and documentation through the admindocs application ( https://docs.djangoproject.com/en/dev/ref/contrib/admin/admindocs/ ):

The Djangos application admindocs documentation from the docstrings of models, views, template tags and template filters for any application in INSTALLED_APPS and makes this documentation accessible from the Django Administrator.

+1
source

Source: https://habr.com/ru/post/888087/


All Articles