Cannot assign "’somedata’": "otherdatal" must be a "" instance.`

  django, django-models, instance, python

is it possible to insert the session value to the foreign key.?
here i have 2 models

class candidate(models.Model):
    fname=models.CharField("First name ",max_length=20,default="")
    lname=models.CharField("Last name ",max_length=20,default="")
    email=models.EmailField("Email ",max_length=254,primary_key=True)
    password=models.CharField("Password ",max_length=100,default="")
    
    def __str__(self):
        return self.email #self.fname+" " +self.lname

here iam taking the email from above model as a session
and trying to put this session value to the foreign key field of the below model

class canDetails(models.Model):
    candEmail=models.ForeignKey(candidate,on_delete=models.CASCADE)
    location=models.CharField("location ",max_length=30)
    role=models.CharField("role ",max_length=20)
    cv=models.FileField(upload_to="media/canDetails/")

    def __str__(self):
        return self.candEmail

but here i am getting error like Cannot assign "'[email protected]'": "canDetails.candEmail" must be a "candidate" instance.

i am trying to get all the details from candidate model and candDetails model at once thats why i using pf and fk here,so is it the right way i am following…?
how can i deal with this ? any suggestions pls.?

Source: Python Questions

LEAVE A COMMENT