I have a requirement where a user uploads files to the File collection
class File(Document):
user = ReferenceField(User)
file = FileField()
type = StringField(choices = ('project', 'uploads'))
The user can then submit a file for acceptance to a project. If the file is accepted, it is then copied and stored in the Project collection.
class Project(Document):
file = ReferenceField(File)
file = File.objects(id = id)
copy = File(user = current_user, file = file.file, type = 'project').save()
Project(file = copy).save()
However, if the user decides to clean out his Uploads folder,
files = File.objects(user = current_user, type = 'uploads')
files.delete()
he is prevented from removing files that were submitted to the Project collection. What is the best way to avoid this? Is there a way to copy a file such each file has a 1:1 correspondence with an entry in a collection? Then removing a document from a collection will also remove the file.