title: How to get user object by email filtering in Django
body: <p>I am trying to get a specific user in Django via email filtering using default user model. I am doing the following in my views.py but it is not working:</p>
  
  <pre><code>def shareCode(request):
      if request.method=="POST":
          email  = request.POST.get("mail")
          print(email)
  
          id =  int(request.POST.get('id'))
          user  = User.objects.get(email = email)
          obj = Code.objects.get(pk=id,user = user.id)
          res = {"shared":"fasle"}
          obj2 = Code(name=obj.name,code=obj.code,shared=True)
          obj2.save()
          res = {
              "shared":True
          }
          return HttpResponse(json.dumps(res))
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>    class Code(models.Model):
          name = models.CharField(max_length=255)
          code = models.TextField()
          user = models.ForeignKey(User,on_delete=models.CASCADE)
          shared = models.BooleanField(default=False)
  </code></pre>
  
  <p>but its getting be following error</p>
  
  <pre><code>Internal Server Error: /editor/share
  Traceback (most recent call last):
    File "D:\stocksapp\winenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
      response = get_response(request)
    File "D:\stocksapp\winenv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "D:\stocksapp\winenv\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "D:\stocksapp\main\views.py", line 138, in shareCode
      obj = Code.objects.get(id=id,user = user)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
      return getattr(self.get_queryset(), name)(*args, **kwargs)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\query.py", line 390, in get
      clone = self.filter(*args, **kwargs)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\query.py", line 844, in filter
      return self._filter_or_exclude(False, *args, **kwargs)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\query.py", line 862, in _filter_or_exclude
      clone.query.add_q(Q(*args, **kwargs))
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\sql\query.py", line 1263, in add_q
      clause, _ = self._add_q(q_object, self.used_aliases)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\sql\query.py", line 1287, in _add_q
      split_subq=split_subq,
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\sql\query.py", line 1225, in build_filter
      condition = self.build_lookup(lookups, col, value)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\sql\query.py", line 1096, in build_lookup
      lookup = lookup_class(lhs, rhs)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\lookups.py", line 20, in __init__
      self.rhs = self.get_prep_lookup()
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\lookups.py", line 70, in get_prep_lookup
      return self.lhs.output_field.get_prep_value(self.rhs)
    File "D:\stocksapp\winenv\lib\site-packages\django\db\models\fields\__init__.py", line 965, in get_prep_value
      return int(value)
  ValueError: invalid literal for int() with base 10: 'code'
  </code></pre>
  
  <p>Any help will be appreciated</p>