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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:09:10+00:00 2026-06-05T10:09:10+00:00

In my app,I need to associate the User with a user-selected-filename A user can

  • 0

In my app,I need to associate the User with a user-selected-filename

A user can only select one filename.But the same filename may be selected by many users

So,database table may be like this

auth_user(created by django.contrib.auth)

-----------------------------------------
id | username | first_name | last_name | ...
------------------------------------------
1  |  bert     |  bert     | russel    |...
------------------------------------------
2  |  jon      |  jon      | snow      | ...
-------------------------------------------
3  |  alice    | alice     | tanner    | ...

userfile table

-----------------------------------------------
id  | filename              
------------------------------------------------
1   |  '/clips/summary.mp4'  
------------------------------------------------
2   | '/clips/intro.mp4'    
------------------------------------------------

user_userfile table

-----------------------------------
 user_id   |    userfile_id
-----------------------------------
   1       |    1
-----------------------------------
   2       |    1
-----------------------------------
   3       |    2
-----------------------------------

It seems that userfile--user is a 1 - n relation . 1 userfile can be associated with many users.

So,what should I use to represent this relationship?
In class UserFile given below ,if I use

user = db.models.ForeignKey(django.contrib.auth.User)

That will only make the reverse relationship (ie n-1 for userfile--user)

class UserFile(db.models.Model):
    filename = db.models.CharField()
    user     = ??
  • 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-05T10:09:11+00:00Added an answer on June 5, 2026 at 10:09 am

    I would really like a OneToMany field too. But the reason there is no such field in Django i believe is that this would create an FK on the table of the related model:

    1. That’s sort of confusing

    2. Syncdb wouldn’t be able to add the column to the existing table

    The solution to add the FK on a related model is to use an “unsupported” feature:

    from django.contrib.auth.models import User
    models.ForeignKey(Badge, null=True, blank=True).contribute_to_class(User, 'badge')
    

    Then you should add migrate auth_user to add the FK.

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

Sidebar

Related Questions

I'm writing an app where I need to associate data with user pairs. For
my app need to show user scrollable menu bar under tab bar like fox
I have a navigation app that has many screens the user navigates to. A
I'm current developing web-app that allows a user to associate their account with their
Previously I read posts with same problem but my question persists. My app needs
Problem Throughout my app I need to download files. In some cases I only
I have an application in which the user can select from local video files.
For my GAE app I need to do some natural language processing to extract
In my app I need to draw a widget contents onto Bitmap. The code(pseudo)
My android app project need to add a new function of saving the click

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.