我对 Django 很陌生,这让我很难过。
我正在开发一个调度工具,到目前为止有两个模型:
#----------------------------------------------------------------------------------
class ReccurenceEvent(models.Model):
"""
A recurrence event defined an event which recurses over a period of time. The pattern of the recursion
is defined within the rec_type attribute.
"""
event_id = models.IntegerField(primary_key=True)
start_date = models.DateTimeField()
end_date = models.DateTimeField()
text = models.CharField(max_length=30)
rec_type = models.CharField(max_length=32)
event_length = models.BigIntegerField(null=True)
#----------------------------------------------------------------------------------
class Event(models.Model):
"""
A an event represents an independent calender event.
If the event relates to a series, the p_id points to a particular ReccurencePattern
"""
event_id = models.IntegerField(primary_key=True)
start_date = models.DateTimeField()
end_date = models.DateTimeField()
text = models.CharField(max_length=30)
rec_type = models.CharField(max_length=32)
event_length = models.BigIntegerField(null=True)
event_pid = models.ForeignKey(ReccurenceEvent, null=True)
在某些情况下,我想将父事件 id (event_pid) 分配给事件,但这应该是一个整数值,而不是对对象的引用。
当我执行以下操作时:
e.event_pid = event_pid
我收到以下消息:
Cannot assign "u'1359741862566'": "Event.event_pid" must be a "ReccurenceEvent" instance.
好的,但是如果提供一个重复实例:
e.event_pid = ReccurenceEvent.objects.get(event_id = event_pid)
我没有在响应中存储我需要的整数值。
有人能指出我哪里出错了吗?