2👍
✅
In views.py (if your AUTH_USER_MODEL configured to Account)
@login_required(login_url='/accounts/login/', template_name='market/postad.html')
def newProduct(request):
product_form = ProductForm(request.POST or None, request.FILES or None)
if(request.method =='POST'):
if product_form.is_valid():
product = product_form.save(commit=False)
product.userid = Account.objects.get_or_create(user=request.user)
product.save()
else:
print product_form.errors
return render(request, template_name, {'product_form':product_form} )
Source:stackexchange.com