0
を必要と私は次のような形式があります除外フィールドはまだ
:私はフォームを送信すると、私はエラーを取得する@python_2_unicode_compatible
class Post(models.Model):
entity = models.ForeignKey('companies.Entity')
title = models.CharField('Post Title', max_length=128, unique=True)
desc = models.TextField('Description', blank=True, null=True)
post_type = models.IntegerField(choices=POST_CHOICES)
image = models.ImageField('Post Image', upload_to='post', blank=True, null=True)
url = models.URLField(max_length=255, blank=True, null=True)
slug = models.SlugField(blank=True, null=True, unique=True)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
:
class PostForm(forms.ModelForm):
post_type = forms.ChoiceField(widget=forms.RadioSelect(attrs={'name': 'radioInline'}), choices=POST_CHOICES)
class Meta:
model = Post
fields = ('title','desc','image','url',)
を私は次のモデルを持っています
post_typeフィールドエラー:このフィールドは必須です。
form.is_validメソッドのあとにこのフィールドを設定します。
このフィールドは必須フィールドタプルには含まれていないので、必須ではありませんか?
私はまた、追加しようとしている:私は同じエラーを取得しますが
post_type = models.IntegerField(choices=POST_CHOICES, blank=True)
。
何か他には何かがありますか?
post_typeをnullにしてからnullをtrueにする場合は、モデルで必要なフィールドとフィールドに異なるフィールドが必要です。そうでなければ、is_validの呼び出しの前にデータを設定できます。その後、あなたはこのフィールドを気にしないので、明らかに正しいでしょうか? – Quentin