title: ValueError: Cannot assign "4749890231992320L": "Student.user" must be a "User" instance. (Django + custom models)
body: <p>I'm having issues with using <code>Model.objects.get</code> with a custom model that includes a standard Django user as one of the fields. Here are the basic attributes:</p>
  
  <pre><code>class Student(models.Model):
      user = models.ForeignKey(User, unique=True)
      school = models.ForeignKey(School)
      isHead = models.BooleanField()
  </code></pre>
  
  <p>I made a new <code>School</code>, <code>User</code>, and <code>Student</code>, and saved them all without problem. So I typed the following into a <code>manage.py shell</code>, where <code>new</code> is the variable for the <code>User</code> object:</p>
  
  <pre><code>Student.objects.get(user = new)
  </code></pre>
  
  <p>Then, I get the error:</p>
  
  <pre><code>ValueError: Cannot assign "5312840185413632L": "Student.user" must be a "User" instance.
  </code></pre>
  
  <p>I've done some research, and I understand the above to mean that I'm passing something that is <em>not</em> a <code>User</code> object as the parameter. However, I've defined </p>
  
  <pre><code>new = User(username="new user")
  </code></pre>
  
  <p>so I can't figure out what I'm doing incorrectly.</p>
  
  <p>Any help would be greatly appreciated. If it helps, I'm working within Eclipse, which is new to me, although Django/python is not.</p>
  
  <p>EDIT: Here is my the full code for the custom classes:</p>
  
  <pre><code>class School(models.Model):
      def level(self):
          return get_max_triangle_num_less_than(self.rep / SCHOOL_REP_LEVEL_MODIFIER)
  
      name = models.CharField(max_length=64)
      # Rep could also be a DecimalField (needs max_digits and decimal_places specified)
      rep = models.IntegerField(default = 0)
      num_students = models.IntegerField(default = 0)
  
      def __init__(self, name, *args, **kwargs):
          models.Model.__init__(self, *args, **kwargs)
          self.name = name
  
      def __str__(self, *args, **kwargs):
          return self.name + ", " + str(self.num_students) + " students"
  
  class Student(models.Model):
  
      def level(self):
          return get_max_triangle_num_less_than(self.rep / STUDENT_REP_LEVEL_MODIFIER)
  
      user = models.ForeignKey(User, unique=True)
      school = models.ForeignKey(School)
      isHead = models.BooleanField()
  
      referral_code = models.CharField(max_length=128, unique=True)
      referred_by = models.ForeignKey(User, blank=True, null=True)
  
      rep = models.IntegerField(default = 0)
  
      def __init__(self, user, school, referred_by = None, *args, **kwargs):
          models.Model.__init__(self, *args, **kwargs)
          self.user = user
          self.school = school
          if referred_by:
              self.referred_by = referred_by
  
          # This automatically creates a custom string of letters/numbers -- I thought it was 
          #  the easiest way to make a custom "referral code" which can be used to link a 
          #  registration to the referrer
          self.referral_code = str(uuid.uuid4())
  
          self.school.num_students += 1
  
      def __str__(self):
          something = str(self.user.username)
          if self.isHead:
              something += ", Head at "
          else:
              something += ", at "
          something += self.school.name + ", " + str(self.rep) + " rep points"
          return something
  </code></pre>
  
  <p>And here is what I type into the shell + traceback:</p>
  
  <pre><code>&gt;&gt;&gt; from spudmart.campusrep.models import User, School, Student
  &gt;&gt;&gt; usr = User(username="user")
  &gt;&gt;&gt; usr.save()
  &gt;&gt;&gt; sch = School(name = "school")
  &gt;&gt;&gt; sch.save()
  &gt;&gt;&gt; stu = Student(user = usr, school = sch)
  &gt;&gt;&gt; stu.save()
  &gt;&gt;&gt; Student.objects.get(user = usr)
  
  Traceback (most recent call last):
    File "&lt;console&gt;", line 1, in &lt;module&gt;
    File "/Users/Lucy/Code/Git/spudder/spudmart/src/django/db/models/manager.py", line 132, in get
      return self.get_query_set().get(*args, **kwargs)
    File "/Users/Lucy/Code/Git/spudder/spudmart/src/django/db/models/query.py", line 346, in get
      num = len(clone)
    File "/Users/Lucy/Code/Git/spudder/spudmart/src/django/db/models/query.py", line 82, in __len__
      self._result_cache = list(self.iterator())
    File "/Users/Lucy/Code/Git/spudder/spudmart/src/django/db/models/query.py", line 288, in iterator
      obj = model(*row[index_start:aggregate_start], **{'__entity_exists': True})
    File "/Users/Lucy/Code/Git/spudder/spudmart/src/spudmart/campusrep/models.py", line 51, in __init__
      self.user = user
    File "/Users/Lucy/Code/Git/spudder/spudmart/src/django/db/models/fields/related.py", line 331, in __set__
      self.field.name, self.field.rel.to._meta.object_name))
  ValueError: Cannot assign "4661929301770240L": "Student.user" must be a "User" instance.
  </code></pre>