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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:47:41+00:00 2026-06-18T02:47:41+00:00

I have a table like this: +—-+———-+———-+—————-+———————————-+ | id | users_id | files_id |

  • 0

I have a table like this:

+----+----------+----------+----------------+----------------------------------+
| id | users_id | files_id | shared_user_id | shared_date                      |
+----+----------+----------+----------------+----------------------------------+
|  3 |        1 |        1 |              2 | 2013-01-31 14:27:06.523908+00:00 |
|  2 |        1 |        1 |              2 | 2013-01-31 14:25:37.760192+00:00 |
|  4 |        1 |        3 |              2 | 2013-01-31 14:46:01.089560+00:00 |
|  5 |        1 |        1 |              3 | 2013-01-31 14:50:54.917337+00:00 |

Now I want to know the owner of each files who shared the file. For file 1, users_id is 1. I want to get the name of users_id 1 from the default Django auth_user table. I want to get the usernames for each file. How can I do that?

#models.py
from django.db import models
from django.contrib.auth.models import User

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_overview = models.IntegerField()
    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()

class Host(models.Model):
    name = models.TextField()
    full_path = models.TextField()
  • 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-18T02:47:42+00:00Added an answer on June 18, 2026 at 2:47 am

    As I’ve said to you before, your model structure is a bit odd – in particular, Share.shared_user should be a ForeignKey, not an IntegerField. In this case, you could help things by making users a ManyToManyField from File to User, using Share as the through table:

    class File(models.Model):
        users = models.ManyToManyField(User, through='Share')
    

    Now given a File instance you can simply do:

    my_file.users.count()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table like this Id Student Test_Start Test_End 1 A 2013-01-08 15:00:17.100 2013-01-08
I have a table like this |customer_reference|date_and_time| 111 2013-01-01 111 2013-01-02 111 2013-01-03 222
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have a table like this ID Name IsDeleted 1 Yogesh Null 2 Goldy
I have a table like this : +-------+------------+------+-----+---------+-------+ | Field | Type | Null
I have a table like this: ID country ------------- 1 US 2 Japan 3
I have a table like this: id | id_parent | tag_name 0 | |
I have a table like this: CREATE TABLE book_info ( book_id VARCHAR(32) not null,
I have a table like this: <table> <tr> <td> A-1 </td> <td> A-2 </td>

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.