Django models in file sharing system

89 views
Skip to first unread message

Vasu Dev Garg

unread,
Dec 10, 2015, 1:06:00 PM12/10/15
to Django users
models.py :

 `class Document(models.Model):
     docfile = models.FileField(upload_to='documents/%Y/%m/%d')
     user = models.ForeignKey(User, null=False, blank= False)
`


I have created a model for file upload as shown above. docfile is the field that represents file to be uploaded and user field stores the name of the user that is uploading the file.I want the additional fields so that file uploaded is visible to the ones with whom it has been shared. Tell me the fields for achieving the sharing task.

Mike Dewhirst

unread,
Dec 10, 2015, 7:35:51 PM12/10/15
to django...@googlegroups.com
On 11/12/2015 5:00 AM, Vasu Dev Garg wrote:
> models.py :
>
> Â `class Document(models.Model):
> Â Â Â docfile = models.FileField(upload_to='documents/%Y/%m/%d')
> Â Â Â user = models.ForeignKey(User, null=False, blank= False)
> `
>
>
> I have created a model for file upload as shown above. docfile is the
> field that represents file to be uploaded and user field stores the name
> of the user that is uploading the file.I want the additional fields so
> that file uploaded is visible to the ones with whom it has been shared.
> Tell me the fields for achieving the sharing task.

Maybe you should use a ManyToManyField so many users may be linked to
any Document.

https://docs.djangoproject.com/en/1.8/ref/models/fields/#manytomanyfield

eg sharing = models.ManyToManyField('User')


>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/84c40695-9652-443a-98d0-b5d416f673ea%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/84c40695-9652-443a-98d0-b5d416f673ea%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Vasu Dev Garg

unread,
Dec 12, 2015, 2:47:33 AM12/12/15
to Django users
creating a sharing manytomany field is right but how to call it in views and verify that user filled in the form exists?
Reply all
Reply to author
Forward
0 new messages