On my current project I want the user to be able to fill in forms without having to sign up first (to make them more likely to use the service).
On the below view I'm trying to either save the registered user with the form data, or if the user isn't registered save the Session ID as a temporary user id.
However when I try to use the session ID it returns none. I'm not sure why the data is missing? (Session have the default django setup in apps and middleware as per the docs). Note when a user is logged in it seem to have a user id but not when no user is logged in.
form_class = ServiceTypeForm
template_name = "standard_form.html"
success_url = '/'
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.temp_user = self.request.session.session_key
online_account = form.cleaned_data['online_account']
supplier1 = models.OneToOneField(SupplierAccount)
supplier2 = models.OneToOneField(SupplierAccount)
supplier3 = models.OneToOneField(SupplierAccount)
online_account = models.BooleanField()
address = models.OneToOneField(Address, null=True)
temp_user = models.CharField(max_length=255, null=True)
user = models.OneToOneField(settings.AUTH_USER_MODEL, null=True, default=None)
supplier = models.ForeignKey(Supplier)
username = models.CharField(max_length=255)
password = models.CharField(max_length=255)
# BOOL_CHOICES = ((False, 'No'), (True, 'Yes'))
# online_account = f