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 9167903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:30:15+00:00 2026-06-17T15:30:15+00:00

I have two tables in Django: First one is file which has the file

  • 0

I have two tables in Django: First one is file which has the file information and second one is share which has the shared information:
files_id is foreign key to Share table:
Now, I want to retrieve file information(from File table) which has files_id in shared table. How can I do that?

#models.py
class File(models.Model):
    users = models.ForeignKey(User)
    file_name = models.CharField(max_length=100)
    type = models.CharField(max_length=10)
    source = models.CharField(max_length=100)
    start_date = models.TextField()
    end_date = models.TextField()
    duration = models.TextField()
    size = models.TextField()
    flag = models.TextField()
    #delete_date = models.CharField(max_length=100, null=True, blank=True)

class Share(models.Model):
    users = models.ForeignKey(User)
    files = models.ForeignKey(File)
    shared_user_id = models.IntegerField()
    shared_date = models.TextField()

I want to get the file_information with users_id is log_id and get the shared_date too. I get log_id as: log_id = request.user.id

  • 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-17T15:30:16+00:00Added an answer on June 17, 2026 at 3:30 pm

    I have made some changes to your models to remove confusion of plural names for user and file. I think you named them that because you already have some database.

    #models.py
    class File(models.Model):
        user = models.ForeignKey(User, db_column="users_id")
        file_name = models.CharField(max_length=100)
        type = models.CharField(max_length=10)
        source = models.CharField(max_length=100)
        start_date = models.TextField()
        end_date = models.TextField()
        duration = models.TextField()
        size = models.TextField()
        flag = models.TextField()
        #delete_date = models.CharField(max_length=100, null=True, blank=True)
    
    class Share(models.Model):
        user = models.ForeignKey(User,db_column="users_id")
        file = models.ForeignKey(File, db_column="files_id")
        shared_user_id = models.IntegerField()
        shared_date = models.TextField()
    

    So, from above two models, it appears that File object is created by one User which can be shared bu other users. Since you have files_id somehow, following query should work

    file = File.objects.get(id=files_id)
    # Assuming one file is shared only ones by an user
    # otherwise you should use filter instead of get
    shared_file = Share.objects.get(file=file, user=request.user)
    

    Why are you using TextField for storing DateTime? You should use DateTimeField.

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

Sidebar

Related Questions

I have two simple tables in Django which looks like: class Session(models.Model): id =
Is is possible to programatically join two tables using Django's ORM? I have two
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables in my MySQL database, one is a library of all
I have two Postgres databases. In one I have two tables, each with about
Say I have two tables (I am using Django, but this question is mostly
I have problem about django template-db query relationship. For example, I created two tables
I have two tables in my database (django: models in my app) as follows:
I have two tables, each referring the other (created by django ORM). Each table
I have two tables images2 and image_data So the goal is to have 1

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.