Ошибка: Object of type User is not JSON serializable
Пытаюсь передать request.user в функцию, но появляется ошибка
Object of type User is not JSON serializable
Подскажите пожалуйста как правильно сделать сериализацию, каким способом и где можно подробнее об этом почитать. Или можно как-то исправить это другим способом?
views.py
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from .forms import *
from django.views.generic import DetailView, FormView
from django.http import HttpResponse, HttpResponseRedirect
from instabot import Bot
from django.contrib.auth.mixins import LoginRequiredMixin
from .tasks import check_account
import json
class accounts(LoginRequiredMixin, FormView):
model = InstAcc
form_class = FormInstAcc
template_name = 'primeApp/accounts.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['accs'] = InstAcc.objects.filter(user=self.request.user)
return context
def post(self, request, *args, **kwargs):
form = FormInstAcc(request.POST or None)
if request.method == 'POST' and form.is_valid():
data = form.cleaned_data
new_form = form.save(commit=False)
new_form = request.user
new_form.save()
login = data["login_inst"]
password = data["password_inst"]
status = check_account.delay(login, password, user)
print(status)
return HttpResponseRedirect(self.request.path_info)
return HttpResponseRedirect(self.request.path_info)
Функция
def check_account(login, password, user_s):
error = False
try:
bot = Bot()
bot.login(username=login, password=password, is_threaded=True, force=True)
user_info = bot.get_user_info(login)
print('starttttt')
b = InstAcc(user=user_s,
login_inst=login,
password_inst=password,
username=user_info["username"],
follower_count=user_info["follower_count"],
following_count=user_info["following_count"],
img=user_info["profile_pic_url"])
b.save()
print('successsss')
except:
error = True
print('error_add_account')
InstAcc.objects.get(login_inst=login).delete()
print('errrrror')
return error