我正在尝试使用 djongo 创建一个带有 django 的应用程序来与 mongodb 进行通信。我有以下模型:
from djongo import models
from django import forms
class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
class Meta:
abstract = True
class BlogForm(forms.ModelForm):
class Meta:
model = Blog
fields = (
'__all__'
)
class MetaData(models.Model):
# pub_date = models.DateField()
# mod_date = models.DateField()
n_pingbacks = models.CharField(max_length=255)
rating = models.CharField(max_length=255)
class Meta:
abstract = True
class MetaDataForm(forms.ModelForm):
class Meta:
model = MetaData
fields = (
'__all__'
)
class Author(models.Model):
name = models.CharField(max_length=200)
email = models.EmailField()
def __str__(self):
return self.name
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = (
'name', 'email'
)
class Entry(models.Model):
blog = models.EmbeddedModelField(
model_container=Blog,
model_form_class=BlogForm
)
meta_data = models.EmbeddedModelField(
model_container=MetaData,
model_form_class=MetaDataForm
)
headline = models.CharField(max_length=255)
body_text = models.TextField()
authors = models.ArrayReferenceField(
to=Author,
on_delete=models.CASCADE,
)
n_comments = models.CharField(max_length=255)
def __str__(self):
return self.headline
但是当我使用 django admin 创建一个新条目时,我得到的错误是:
/admin/app/entry/add/ int() 参数的 TypeError 必须是字符串、类似字节的对象或数字,而不是“设置”请求方法:POST 请求 URL: http://localhost:8000/admin/ app/entry/add/ Django 版本:2.1.3 异常类型:TypeError 异常值:int() 参数必须是字符串、类似字节的对象或数字,而不是“设置”异常位置:C:\Users\scg \Documents\Rest_project\envschool\lib\site-packages\django\db\models\fields__init__.py 在 get_prep_value,第 965 行 Python 可执行文件:C:\Users\scg\Documents\Rest_project\envschool\Scripts\python.exe Python 版本:3.7.1 Python 路径:
['C:\Users\scg\Documents\Rest_project\djongoproj2', 'C:\Users\scg\Documents\Rest_project\envschool\Scripts\python37.zip', 'C:\Users\scg\AppData\Local\Programs \Python\Python37-32\DLLs','C:\Users\scg\AppData\Local\Programs\Python\Python37-32\lib','C:\Users\scg\AppData\Local\Programs\Python\Python37 -32', 'C:\Users\scg\Documents\Rest_project\envschool', 'C:\Users\scg\Documents\Rest_project\envschool\lib\site-packages']
请问我该如何解决这个问题。
我正在使用 django 2.1.3 和 djongo 1.2.30