In my application, I need to associate Userwithuser-selected-filename
A user can select only one file name. But the same file name can be chosen by many users.
So the database table may be like this
auth_user (created django.contrib.auth)
-----------------------------------------
id | username | first_name | last_name | ...
------------------------------------------
1 | bert | bert | russel |...
------------------------------------------
2 | jon | jon | snow | ...
-------------------------------------------
3 | alice | alice | tanner | ...
user file table
id | filename
1 | '/clips/summary.mp4'
2 | '/clips/intro.mp4'
user_userfile table
user_id | userfile_id
1 | 1
2 | 1
3 | 2
That seems to be userfile--useran attitude 1 - n. 1 user file can be associated with many users.
So what should I use to represent this relationship? In the UserFile class below if I use
user = db.models.ForeignKey(django.contrib.auth.User)
This will only lead to an inverse relation (i.e. n-1for userfile--user)
class UserFile(db.models.Model):
filename = db.models.CharField()
user = ??
source
share