0

我有一个表单,希望不显示用户字段。

模型.py

class Questions(models.Model):
    user=models.ForeignKey(User)
    category=models.ForeignKey(Categories)
    question=models.TextField(max_length=500)
    created_date=models.DateTimeField('date created')
    def __unicode__(self):
        return "%s%s" %(self.question,self.created_date)

class QuestionsForm(ModelForm):
        class Meta:
            model = Questions
        widgets = {
            'question': TextInput(attrs={'placeholder': 'Add question here'})
        }
        exclude=('user',)

我尝试排除但该字段仍然出现。怎么做??

4

1 回答 1

3

注意你的缩进:

class QuestionsForm(ModelForm):
    class Meta:
        model = Questions
        widgets = {
            'question': TextInput(attrs={'placeholder': 'Add question here'})
        }
        exclude=('user',)
于 2013-06-14T12:57:32.333 回答