1👍
✅
You try to specify the model UsersByIP
this way usersbyip=request.META.get('REMOTE_ADDR')
but usersbyip
expects either the id of the model or the model instance itself not a field of the model. You should pass it the ip_user
variable of yours (after making sure it is saved):
ip_user, created = UsersByIP.objects.get_or_create(ip_user=request.META.get('REMOTE_ADDR'))
if not request.user.is_authenticated:
__, created = Video.viewers_by_ip.through.objects.get_or_create(
video=data,
usersbyip=ip_user
)
Source:stackexchange.com