Django-MongoEngine中的关键字参数错误无效

时间:2014-10-24 12:07:52

标签: python django mongodb mongoengine

我正在尝试使用MongoEngine配置Django。我创建了模型并对settings.py文件进行了必要的更改。但是,每当我尝试在python shell中创建一个新实例时,它都会给我同样的错误:

TypeError: 'x' is an invalid keyword argument for this function

我的models.py如下所示:

from django.db import models
from mongoengine import *
from gauravgarden.settings import DBNAME

connect(DBNAME)

class Event(models.Model):
    event_date = DateTimeField(required=True)
    event = StringField(max_length=350, required=True)
    notes = ListField()

    def __str__(self):              # __unicode__ on Python 2
        return self.event


class Extras(models.Model):
    extra_params = StringField(max_length=150, required=True)
    cost = DecimalField(precision=2, rounding="ROUND_DOWN")

    def __str__(self):              # __unicode__ on Python 2
        return self.extra_params

class Itinerary(models.Model):
    booking_date = DateTimeField(required=True)
    customer_name = StringField(max_length=300, required=True)
    plan = ListField(EmbeddedDocumentField('Event'))
    extras = ListField(EmbeddedDocumentField('Extras'))

    def __str__(self):              # __unicode__ on Python 2
        return self.customer_name

我正在尝试在python manage.py shell中执行以下查询。

new_event = Event(event_date = datetime.datetime(2014, 10, 30, 11, 30, 00), event = "Welcome/Meet & Greet", notes = ["Hall should be ready", "Keys hand over", "Breakfast layout"])

new_record = Itinerary(booking_date = datetime.datetime(2014, 10, 30, 10, 00, 00), customer_name = "John Diggle", plan = [], extras = [])

错误消息显示event_dateextrasbooking_date等是此函数的无效关键字参数。

这里有什么问题?

1 个答案:

答案 0 :(得分:0)

你将Django模型与mongoengine字段混合在一起。你不能这样做:如果你想使用mongoengine,你需要使用他们的Document类。

class Event(Document):
    ...etc...