# Foreingkey - QuerySet value for an exact lookup must be limited to

**URL:** <https://forum.djangoproject.com/t/foreingkey-queryset-value-for-an-exact-lookup-must-be-limited-to/17973>\
**Category:** Getting Started\
**Created:** [January 4, 2023, 1:06am UTC](https://forum.djangoproject.com/t/foreingkey-queryset-value-for-an-exact-lookup-must-be-limited-to/17973 "2023-01-04T01:06:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![julianov](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/julianov/32/3502_2.png) [@julianov](https://forum.djangoproject.com/u/julianov)\
**Post date:** [January 4, 2023, 1:06am UTC](https://forum.djangoproject.com/t/foreingkey-queryset-value-for-an-exact-lookup-must-be-limited-to/17973/1 "2023-01-04T01:06:21Z")

</div>

I’ve implemented the following model that extends the information from Django’s generic User model.

```
class user_data (models.Model):

    user_id = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    client_type= models.IntegerField(default=1, blank=True) 
    name = models.CharField(max_length=200, blank=True)
    last_name = models.CharField(max_length=200, blank=True)
    picture=models.ImageField(upload_to='media/', blank=True)	
    qualification=models.IntegerField(default=0)

```

But when I want to store data in it, I get the following console output

```
'The QuerySet value for an exact lookup must be limited to '
ValueError: The QuerySet value for an exact lookup must be limited to one result using slicing.
 [04/Jan/2023 00:30:28] "POST /completeinfo HTTP/1.1" 500 134219

Traceback (most recent call last):
  File "/home/julian/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/julian/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/julian/.local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/julian/xxxxxxx/xxxxxx/xxxxxxx/xxxxxx/xxxxxxxxx/views.py", line 217, in completeInfo
    userData =user_data.objects.filter(user_id=user).first()
  File "/home/julian/.local/lib/python3.6/site-packages/django/db/models/query.py", line 674, in first
    for obj in (self if self.ordered else self.order_by('pk'))[:1]:

```

this is the method:

```
  @csrf_exempt 
  def completeInfo (request): 
      if request.method == 'POST':
          user=User.objects.filter(email=request.POST.get("email")) 
          if user: 
              userData =user_data.objects.filter(user_id=user).first()
              if userData:
                  userData.name=request.POST.get("name")
                  userData.last_name=request.POST.get("surname") 
                  userData.picture= request.FILES.get("image") 
                  userData.qualification=0
                  userData.save()
                  #......

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 4, 2023, 1:43am UTC](https://forum.djangoproject.com/t/foreingkey-queryset-value-for-an-exact-lookup-must-be-limited-to/17973/2 "2023-01-04T01:43:00Z")

</div>

The basic problem is that you’ve got the relationship defined as a many-to-one where each `User` could have many `user_data` related to it. What you’re likely looking for is a one-to-one relationship between the two models. Review the docs at [Customizing authentication in Django | Django documentation | Django](https://docs.djangoproject.com/en/4.1/topics/auth/customizing/#extending-the-existing-user-model).

Side note: I would encourage you to adopt Python and Django’s naming conventions for classes. This means your profile class would more appropriately be named `UserData`.

Side note #2: Once you have the proper relationship defined between the two models, it’s no longer necessary to write a query to access data associated with the related object. The ORM provides direct bidirectional access between objects related by a one-to-one relationship.

---

<div class="post-metadata">

**Author:** ![julianov](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/julianov/32/3502_2.png) [@julianov](https://forum.djangoproject.com/u/julianov)\
**Post date:** [January 4, 2023, 1:49am UTC](https://forum.djangoproject.com/t/foreingkey-queryset-value-for-an-exact-lookup-must-be-limited-to/17973/3 "2023-01-04T01:49:14Z")

</div>

Thanks for the reply. Is it possible to have more than one model with a one-to-one relationship with the User model?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 4, 2023, 1:53am UTC](https://forum.djangoproject.com/t/foreingkey-queryset-value-for-an-exact-lookup-must-be-limited-to/17973/4 "2023-01-04T01:53:11Z")

</div>

Absolutely. What leads you to believe that there can’t?
