私は Django の Class-Based-View で練習しています。
一般的な CreateView で練習しているときに、「fields」属性
が機能しない理由を理解するのに苦労しています... CreateView を使用して投稿作成ページを作成しようとしていますが
、「post_title」フィールドと「post_content」フィールドのみが必要です投稿ページに表示されるようにします (つまり、
フォームの「user」フィールドと「post_date」フィールドを省略したくありません)。「フィールド」属性がこれを定義する適切な場所であると確信していますが、何らかの理由で、4 つのフィールドすべてが投稿フォームに表示されます。
ここに私のコードがあります:
models.py
class Post(models.Model):
user = models.ForeignKey(User)
post_title = models.CharField(max_length=200)
post_content = models.CharField(max_length=500)
post_date = models.DateTimeField('date posted')
ビュー.py
class PostCreate(CreateView):
template_name = 'app_blog/post_save_form.html'
model = Post
fields = ['post_title', 'post_content']
4 つのフィールドすべてが表示される理由は何か分かりますか? ありがとう :)