【发布时间】:2023-03-07 13:28:01
【问题描述】:
所以我正在处理 Django 中的 model.py,但我遇到了 2 个 pylint 错误。 我不明白为什么?这是 pylint 的问题还是我在代码中做错了什么。
E1120:No value for argument 'on_delete' in constructor call
E1136:Value 'self.text' is unsubscriptable
第一个在第 19 行,在 Entry 中 topic = models.ForeignKey(Topic)
第二个在第24行self.text[:50]
如果我删除入口类,代码就可以工作
from django.db import models
# Create your models here.
class Topic(models.Model):
"""A topic the user is learning about"""
text = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""Return a string representation of the model."""
return self.text
class Entry(models.Model):
"""Something specific learned about a topic"""
topic = models.ForeignKey(Topic)
text = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name_plural = "entries"
def __str__(self):
"""Return a string representation of the model."""
return self.text[:50] + "..."
【问题讨论】:
标签: python django python-3.x