我有这个型号:
class EntryBook(models.Model):
status = models.IntegerField(max_length=2)
date = models.DateTimeField(auto_now_add=True, blank=True)
person = models.ForeignKey(Person)
book = models.ForeignKey(Book, related_name="b_entrybook")
topiccenter = models.ForeignKey(TopicCenter, related_name="tc_books")
def __unicode__(self):
return self.book.title
我试图保存新对象:
tc = TopicCenter.objects.get(id=int(tcid))
user = request.user.get_profile()
book = Book.objects.get(id=int(request.POST.get('bookid')))
newbookentry = EntryBook(status=1, person=user, book=book, topiccenter=tc)
newbookentry.save()
我收到错误消息:
TypeError: 'person' is an invalid keyword argument for this function
鉴于person
是模型的正确属性,为什么它是无效的关键字参数?
答案 0 :(得分:0)
newbookentry = EntryBook(status=1, person=user, book=book, topiccenter=tc)
应该是:
newbookentry = EntryBook.objects.create(status=1, person=user, book=book,
topiccenter=tc)