I am using django model forms, the form can be filled even by users who have not signed up, but the submission requires the user being signed up. Here is my models:
class Study(model.Model):
marksobtained = models.CharField(max_length=5)
highestmarks = models.CharField(max_length=5)
teacher = models.CharField(max_length=300)
class StudyForm():
some customisation stuff.
and then the views.py
form = StudiesForm(request.POST or None,
instance=id and Studies.objects.get(id=id))
if form.is_valid():
form.save()
return render(request, 'calculate.html', {'detail': ret_dict, 'amt': amt})
else:
return render(request, 'forms.html', {'form':form})
else:
return render(request, 'forms.html', {'form':form})
Donot bother about the indentation and other stuff in views, this is just a model of what i am trying to do, as can be seen any anonymous user can submit the form as of now, i want it to further modify, as when an anonymous user submits the form, he should first be signed up and then his data should be added to the models.
How can this be implemented?