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

  • Home
  • SEARCH
  • 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 9102359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:21:57+00:00 2026-06-17T01:21:57+00:00

I have a two simple models like this: class User(models.Model): username = models.CharField(max_length=100) #Id

  • 0

I have a two simple models like this:

class User(models.Model):
    username = models.CharField(max_length=100) #Id is automatically generated by Django
    password = models.CharField(max_length=100)

    def __unicode__(self):
        return self.username

class File(models.Model):
    users = models.ManyToManyField(User)
    file_name = models.CharField(max_length=100)
    type = models.CharField(max_length=10)

With the rule of database, bridge entity(table) is created. What I want to know is while inserting the data I want to insert the database with the session_id(foreign key) in my case so that I can retrieve later for my use. How can I do that?

  • 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-17T01:21:58+00:00Added an answer on June 17, 2026 at 1:21 am

    If your trying to add data to ManyToMany Relationships, you’ll have to define the joining table using the through option. Read here for more information.

    Note, however, you shouldn’t be saving the session ID – what are you trying to achieve? The reason for this is a user won’t always have the same sessionID and the data associated with the session (ie, request.session[*]) may be deleted.

    In any case, an example would look something like this

    class User(models.Model):
        username = models.CharField(max_length=100) #Id is automatically generated by Django
        password = models.CharField(max_length=100)
    
        def __unicode__(self):
            return self.username
    
    class File(models.Model):
        users = models.ManyToManyField(User, through='UserFile')
        file_name = models.CharField(max_length=100)
        type = models.CharField(max_length=10)
    
    
    class UserFile(models.Model):
        user = models.ForeignKey(User)
        file = models.ForeignKey(File)
        # Should probably use CharField if you know the length
        session_id = models.TextField()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models like this: class Store(models.Model): name = models.CharField(max_length=255) class Order(models.Model): store
Django newbie here. I have two simple models like this: class Fluff(models.Model): # ....
I have a simple model like this class UserType( models.Model ) : def __unicode__(
I have two models: class Studio(models.Model): name = models.CharField(Studio, max_length=30, unique=True) class Film(models.Model): studio
I have a simple has_one/belongs_to relationship between two models. This is a new association
I have a simple Fluent NHibernate model with two related classes: public class Applicant
I have two models in Rails 3 - a User model and a Profile
I have two models jobs and clients . A user can simple create a
I have the following two models, User.. class User < ActiveRecord::Base has_and_belongs_to_many :sites end
I am using polymorphic relation as i have 3 models like this: class Food

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.