Helo, am trying to get this logic that a user can have many images. User is related to the Items in model and i keep getting this error: What am i doing wrong?
this is the views
def index(request):
users = request.user.items
img = users.images.all().count()
item = Items.objects.filter()
context = {
'user':users,
'imgs':img,
'items':item,
}
return render(request, 'jijiapp/index.html', context)
This is the model
class Items(models.Model):
user = models.ForeignKey(User, on_delete = models.CASCADE, null=True, blank =True)
title = models.CharField(max_length=10, null=True, blank =True)
images = models.ManyToManyField('Images')
post_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class Meta:
ordering =['title',]
# verbos_name ='Items'
class Images(models.Model):
image =models.ImageField(upload_to='media/', null=True, blank=True)
def __str__(self):
return str(self.image)
This is the Traceback:
System check identified no issues (0 silenced).
January 18, 2023 - 23:07:41
Django version 4.0, using settings 'jijiclone.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /home/
Traceback (most recent call last):
File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Christopher\jijiclone\jijiapp\views.py", line 6, in index
users = request.user.items
File "C:\Users\Christopher\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\functional.py", line 249, in inner
return func(self._wrapped, *args)
AttributeError: 'User' object has no attribute 'items'
[18/Jan/2023 23:08:21] "GET /home/ HTTP/1.1" 500 66051