0

Im sure this is probably a simple answer, but I cannot see anything wrong with this!

Im just trying to save a record, and its saying Cannot assign "<User: jason.kinnear>": "Confirmation.user" must be a "User" instance.

This is the code:

u = User.objects.get(pk=18)    
cr = Confirmation(details='...', user=u).save()

Thanks in advance

EDIT: Model Definition for Confirmation

class Confirmation(models.Model):
    number = models.IntegerField(null=True, blank=True)
    user = models.ForeignKey('User')
    details = models.CharField(max_length=250)
    time = models.DateTimeField(auto_now_add=True)

I have tried both

user = models.ForeignKey('User')

and

user = models.ForeignKey(User)

Im not too sure of the difference to be honest

EDIT 2: The User class has been extended like this:

from django.contrib.auth.models import User as BaseUser
class User(BaseUser):
    """Extra user information"""    
    location = models.ForeignKey('Location', null=True, blank=True)
    defaults = models.CharField(null=True, blank=True)
neolaser
  • 6,722
  • 18
  • 57
  • 90

1 Answers1

0

Just so this question has an answer, Ignacio was correct (in the comments). The imported User was not the same. The Django User was extended with another User class and I was importing the wrong one. (Ignacio, if you would like to post an answer I will make that the accepted answer)

neolaser
  • 6,722
  • 18
  • 57
  • 90