[Answered ]-How to automatically add logged in user as creator of product

1👍

You can defer saving the object using .save(commit=False) and modify it by adding the current user as creator before saving, like this:

def product_create_view(request):
    form = ProductForm()
    if request.method == 'POST':
        form = ProductForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.creator = request.user
            instance.save()
    ...

Have a read here for more information on save(commit=False)

Leave a comment