Django Error (Attribute): 'CharField' object has no attribute 'is_related'

元气小坏坏 提交于 2019-12-02 04:43:38

You mixed forms and models. A model does not specify a (HTML) form, it specifies how the database should store data, so you need to use a models.CharField:

class Desc(models.Model):
    description = models.CharField(max_length=250)

Such CharField has no widget assigned to it, this is something you should handle at the form level.

You probably will need to make migrations, since up to this point, there was no description field in your Desc model.

I agree to some extent that it is confusing that the forms have frequently a field with the same name (well those typically are the default form fields for the model field with the same name). The idea is however that model fields specify the columns in a database, whereas form fields specify text boxes, check boxes, etc. in a (HTML) form.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!