int()参数必须是字符串,类似字节的对象或数字,而不是“ builtin_function_or_method”

时间:2019-06-03 04:26:58

标签: django

嗨,人们试图在发起人模型中调用Organizer模型中的模型,而在我无法获取eventDetail的主键时,将组织者模型中的EventDetails称为发起人模型

views.py

if request.method =='POST':
    eventDetail =EventDetails()
    if EventDetails.objects.filter(pk=id,event=request.POST['event_title']).exists():
        event_id =eventDetail.id


    sponsor_ship=SponsorShipDetails(event_id=event_id,event_title=event_title,platinum_sponsor=platinum_sponsor,f_platinum=f_platinum,ex_platinum=ex_platinum,gold_sponsor=gold_sponsor,
                f_gold=f_gold,ex_gold=ex_gold,silver_sponsor=silver_sponsor,f_silver=f_silver,ex_silver=ex_silver)
            sponsor_ship.save()

model.py fromORganiser

class EventDetails(models.Model):

    event = models.CharField(max_length=100)
    no_participant = models.IntegerField()
    event_level = models.CharField(max_length=100)
    eligibility = models.CharField(max_length=100)
    prerequisite = models.TextField(max_length=1500)
    facility = models.CharField(max_length=100)
    event_detail_docs = models.FileField(upload_to='event_details_docs')


class SponsorShipDetails(models.Model):

    event_id =models.OneToOneField(EventDetails,on_delete=models.CASCADE,primary_key=True)
    event_title = models.CharField(max_length=100,default=True)
    platinum_sponsor =models.CharField(max_length=100)
    f_platinum = models.TextField(max_length=1500)
    ex_platinum=models.IntegerField()
    gold_sponsor =models.CharField(max_length=100)
    f_gold =models.TextField(max_length=1500)
    ex_gold = models.IntegerField()
    silver_sponsor= models.CharField(max_length=100)
    f_silver=models.TextField(max_length=1500)
    ex_silver = models.IntegerField()


TypeError at /Organizer/sponsorShipDetails
int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
Request Method: POST
Request URL:    http://localhost:8000/Organizer/sponsorShipDetails
Django Version: 2.1
Exception Type: TypeError
Exception Value:    
int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
Exception `enter code here`Location:    D:\Workspace\lib\site-packages\django\db\models\fields\__init__.py in get_prep_value, line 965
Python Executable:  D:\Workspace\python.exe
Python Version: 3.7.1

1 个答案:

答案 0 :(得分:0)

在SponsorShipDetails类中,您已在EventDetails上声明event_id = OneToOneField,但在EventDetails类中不存在“ event_id”。退出的是“事件”,该事件在SponsorShipDetails中未被当作主键。 更改其中一个的名称