13👍
✅
Your code may look like this:
from django.contrib.auth.decorators import login_required
class QuestionForm(forms.ModelForm):
class Meta:
model = Question
@login_required
def ask(request):
form = QuestionForm(request.POST)
if form.is_valid():
question = form.save(False)
question.userid = request.user
question.save()
#...
Source:stackexchange.com