Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:09:02+00:00 2026-06-16T16:09:02+00:00

I have a django model which stores user and product data from a form

  • 0

I have a django model which stores user and product data from a form input:

def ProductSelection(request, template_name='product_selection.html'):
    ...
    if user.is_authenticated():
        user = request.user
    else:
        # deal with anonymous user info
    project = Project.objects.create(
        user=user,
        product=form.cleaned_data["product"],
        quantity=form.cleaned_data["product_quantity"],
    )

Of course this is fine for authenticated users, but I also want to be able to store anonymous user projects, and if possible, associate them with the user when they eventually register and authenticate.

My idea is to create anonymous user with name = some_variable (timestamp concatenated with a random hash?), then save that username in session data. If I ensure that that session variable, if exists, is used to record all projects activity of that user, I should be able to update the projects with the user’s real credentials when they register.

Is this overly complicated and brittle? Do I risk saving thousands of rows of data unnecessarily? What would be the optimal approach for this common issue?

Any guidance on this would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:09:04+00:00Added an answer on June 16, 2026 at 4:09 pm

    You can use Django’s session framework to store anonymous user data.

    You can then either add a field to your Project model to hold the session_key value for anonymous users,

    project = Project.objects.create(
        user=request.user,  # can be anonymous user
        session=request.session.session_key,
        product=form.cleaned_data["product"],
        quantity=form.cleaned_data["product_quantity"])
    

    or simply store all the data a Project instance would have in the session

    if user.is_authenticated():
        project = Project.objects.create(
            user=request.user,
            product=form.cleaned_data["product"],
            quantity=form.cleaned_data["product_quantity"])
    else:
        # deal with anonymous user info
        request.session['project'] = {
            "product": form.cleaned_data["product"],
            "quantity": form.cleaned_Data["product_quantity"]}
    

    You can retrieve the data from the session later, when creating a proper user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Django Model which retrieves 3 records from a database. The
I have django model which consist of parent child relationship filed I want to
I have a Django model which has a foreign key that is optional. I
I want a Django model to have a date field in which the year,
I'm building a real estate site in Django and have a Home model, which
I have a Django model which I need to hold a callable (in this
I have a model that looks like this and stores data as key-value pairs.
I have a django model which has a load of relatively small fields and
I have a meta class for the Django User model that I use to
I have a form in which the user selects a few items to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.