ich ein Bibliothekssystem ich schreibe, und ich bin immer für diese Nachricht Django Fehler:Ich bin ein Bibliothekssystem zu schreiben, und ich bin immer diese Django Fehlermeldung
Can not assign „‚1‘“: "BookInfo.purchase_sn" muss eine "PurchaseOrderInfo" -Instanz sein.
und es zeigt auch die gleiche Nachricht an author_sn, author_type .... und all foreginkey Felder aus.
Im Folgenden sind meiner Meinung nach und mein Modell.
Was mache ich falsch?
my view is :
def book_add_new(request):
print(request.POST)
book_add_info = BookInfo(book_sn=request.POST['this_bk_sn'],
voucher_sn=int(request.POST['vochr_sn']),
book_genre=request.POST['bk_genre'],
book_state=request.POST['bk_state'],
book_group_sn=request.POST['cpy_group'],
book_classification=request.POST['bk_classification'],
book_primary_title=request.POST['primry_title'],
book_secondary_title=request.POST['scndry_title'],
author_sn=request.POST['authr_sn'],
author_type=request.POST['authr_type_sn'],
publisher_sn=request.POST['puplshr_sn'],
publishing_country=request.POST['cntry_sn'],
book_price=request.POST['bk_price'],
book_isbn=request.POST['bk_isbn'],
book_edition=request.POST['bk_edition'],
publish_date=request.POST['bk_year'],
book_page_count=request.POST['page_count'],
purchase_sn=request.POST['prchs_sn'],
book_in=1)
book_add_info.save()
return render(request, 'book_management/book_add_new_page.html')
My Model:
class PurchaseOrderInfo(models.Model):
purchase_sn = models.IntegerField(primary_key=True)
purchase_owner = models.TextField(blank=True, null=True)
order_date = models.DateField(blank=True, null=True)
order_scan = models.BinaryField(blank=True, null=True)
class Meta:
managed = True
db_table = 'purchase_order_info'
class BookInfo(models.Model):
book_classification = models.TextField(blank=True, null=True)
book_isbn = models.TextField(blank=True, null=True)
book_secondary_title = models.TextField(blank=True, null=True)
book_group_sn = models.IntegerField(blank=True, null=True)
voucher_snv = models.ForeignKey(BookVoucher, models.DO_NOTHING, db_column='voucher_sn', blank=True, null=True)
book_primary_title = models.TextField(blank=True, null=True)
purchase_sn = models.ForeignKey(PurchaseOrderInfo, models.DO_NOTHING, db_column='purchase_sn', blank=True,
null=True)
book_page_count = models.IntegerField(blank=True, null=True)
book_sn = models.IntegerField(primary_key=True)
book_genre = models.ForeignKey(BookGenres, models.DO_NOTHING, db_column='book_genre', blank=True, null=True)
book_state = models.ForeignKey('BookState', models.DO_NOTHING, db_column='book_state', blank=True, null=True)
book_edition = models.IntegerField(blank=True, null=True)
publish_date = models.IntegerField(blank=True, null=True)
book_price = models.TextField(blank=True, null=True) # This field type is a guess.
author_sn = models.ForeignKey(AuthorInfo, models.DO_NOTHING, db_column='author_sn', blank=True, null=True)
author_type = models.ForeignKey(AuthorType, models.DO_NOTHING, db_column='author_type', blank=True, null=True)
publisher_sn = models.ForeignKey(PublisherInfo, models.DO_NOTHING, db_column='publisher_sn', blank=True, null=True)
book_in = models.BooleanField()
publishing_country = models.ForeignKey('CountryInfo', models.DO_NOTHING, db_column='publishing_country', blank=True,
null=True)
def __str__(self):
return self.book_primary_title
class Meta:
managed = True
db_table = 'book_info'