我使用的是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中看到所有带有属性的字段。是否可能
答案 0 :(得分:0)
您可以像这样使用Django的_meta
Api:
>>> Article._meta.get_fields()
<<< { tuple with all fields and types }