4👍
✅
Try ModelName.objects.get(user__username=request.user.username)
Edit: depending on your model relationship, this may result in multiple records, in which case get() would throw an exception, so you could use this instead:
ModelName.objects.filter(user__username=request.user.username)
1👍
Another convenient way to retrieve objects for a specific user is this
user = request.user
objs = user.modelname_set.get(pk=x)
- [Django]-How to set language for django-pagination?
- [Django]-Filtering queryset if one value is greater than another value
- [Django]-Django check if superuser in class-based view
- [Django]-Python manage.py runserver: TypeError: argument 1 must be str not WindowsPath
- [Django]-Spam proof hit counter in Django
Source:stackexchange.com