2017-12-01 12 views
0

を取得しています:私は図書館システムを書いている、と私は、このDjangoのエラーメッセージを取得しています、私は図書館システムを書いている、と私は、このDjangoのエラーメッセージ

は、「『1』」を割り当てることができません。 "BookInfo.purchase_sn"は "PurchaseOrderInfo"インスタンスでなければなりません。

また、author_sn、author_type ....およびすべてのforeginkeyフィールドにも同じメッセージが表示されます。

以下は私のビューと私のモデルです。

私は間違っていますか?

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') 

マイモデル:

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' 

答えて

0

エラーメッセージは正確に何をすべきかを説明します:あなたはpurchase_sn-メンバーにPurchaseOrderInfoを割り当てる必要があります。

PurchaseOrderInfo.getで検索するか、purchase_snを別のPurchaseOrderInfoの主キーに設定した場合は正しく動作します。それは整数であり、次のような文字列ではありません。request.POST

あなたのDjangoの努力と幸運!

関連する問題