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()
#......