当我在查询集中添加值时,我得到了这个错误.
from django.db import models
class Topic(models.Model):
def __init__(self):
topic=models.CharField(max_length=264,unique=True)
def __str__(self):
return self.topic
class Webpage(models.Model):
def __init__(self):
topic=models.ForeignKey(Topic)
name=models.CharField(max_length=264,unique=True)
url=models.URLField(unique=True)
def __str__(self):
return self.name
class AccessRecord(models.Model):
def __init__(self):
name=models.ForeignKey(Webpage)
date=models.DateField()
def __str__(self):
return str(self.date)
#t=Topic(topic="shoaib")
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'topic'
Run Code Online (Sandbox Code Playgroud)
小智 5
你不应该重新定义Django模型init.尝试类似的东西:
class Topic(models.Model):
topic=models.CharField(max_length=264,unique=True)
def __str__(self):
return self.topic
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
781 次 |
| 最近记录: |