[Answered ]-How to make form view with user is foreign key and one model has foreign key relationship with another model?

2👍

Maybe you want something like this

def post_create(request):
    form = ModelForm (request.POST or None, request.FILES or None)
    user = User.objects.get(username=request.user.username)

    if form.is_valid():
        instance = form.save(commit=False)
        instance.asker= user
        instance.save()

   context = {
        "form": form
    }

    return render (request,"blog/create.html",context)

Leave a comment