django shell-plus:如何从命令行

时间:2017-12-17 08:01:52

标签: django django-rest-framework

我使用的是Django Rest Framework,我遇到了repr()函数

当我在Django shell中时

>> from articles.api.serializers import PostSerializer
   print(repr(PostSerializer()))

PostSerializer():
    id = IntegerField(label='ID', read_only=True)
    publish_date = DateTimeField(format='%Y-%m-%d %H:%M UTC')
    is_deleted = BooleanField(required=False)
    title = CharField(max_length=256)
    intro_image = ImageField(allow_null=True, max_length=100, required=False)
    slug = SlugField(max_length=50)
    task_id = CharField(read_only=True)
    qa_bool = BooleanField(label='Allow Q&A', required=False)

假设我有模型文章。我试过了:

>> print(repr(Article))

<class 'articles.models.Article'>

我希望从shell中看到所有带有属性的字段。是否可能

1 个答案:

答案 0 :(得分:0)

您可以像这样使用Django的_meta Api:

>>> Article._meta.get_fields()
<<< { tuple with all fields and types }