2

In my project, I have to handle uploaded files, and I want to have an history of each file version. And to display the history in one view. In my model, each file has a version, a name and a path. This file is related to an other class 'A' by a one to many relationship. I want to have a sort of update function which replace the former file, and I also want to have access to the history with all characteristics of the file and its related model instances (class A).

I don't know how to do. I heard about django reversion and django revisions. What do you advise to me ?

Thank you

user1507156
  • 539
  • 1
  • 7
  • 12

1 Answers1

0

You can do it a couple of ways:

1.You can have a document file model which keeps track of it manually.

class DocumentFile(CachedModel):
   content_type    = models.ForeignKey(ContentType, null=True, blank=True)
   object_id       = models.PositiveIntegerField(null=True, blank=True)
   content_object  = generic.GenericForeignKey(ct_field='content_type', fk_field='object_id')       
   file = models.FileField(upload_to= wherever )
   version = models.PositiveIntegerField(default=1)

   class Meta:
        db_table = 'document_file'
        verbose_name = 'Document File'
        unique_together = ('document', 'version')

You can have a post_save signal called new_version, and update the current revision number on the document

2.You May even use amazon's s3 to store the document, and access it by revision number passing it a get parameter for the revision number(This is a costlier approach)

karthikr
  • 97,368
  • 26
  • 197
  • 188
  • Actually, I need above all to have a track of a lot of models related to the file. The relations between the file model and the others are complex. And updating the file must also update a lot of related models. So I think it doesn't suit my case. But thank you – user1507156 Sep 04 '12 at 11:27
  • You can use Generic Foreign Keys in that case: Check this out - https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1 – karthikr Sep 04 '12 at 12:31