[Fixed]-Django – validate ModelAdmin forms by current user

1👍

i answer with an example:

class X_Form(forms.ModelForm):
    def __init__(self,request,*args,**kwargs):
        super(X_Form, self).__init__(*args,**kwargs)
        self.request = request

    def clean(self):
        user = self.request.user
        ...

and in views

def post_method(request):
    form = X_Form(data=request.POST or None,request=request)
    ...

Of course, If I understand correctly you mean

👤masood

Leave a comment