2

I'would like to store history of my model changes. I found django-reversion extension and it looks quite nice but I have no idea how to intergrate it with tastypie.

My example models:

class Author(models.Model):

    name = models.CharField(max_length=15)
    surname = models.CharField(max_length=20)
    def __unicode__(self):
        return self.name

class Book(models.Model):

    title = models.CharField(max_length=30)
    author = models.ForeignKey(Author)
    isbn = models.CharField(max_length=30)

    def __unicode__(self):
        return self.title

aand resources:

class ResourceAuthor(ModelResource):

    class Meta:
        queryset = Author.objects.all()
        resource_name = "author"

class ResourceBook(ModelResource):

    author = fields.ForeignKey(ResourceAuthor,'author', full = True)

    class Meta:
        queryset = Book.objects.all()
        resource_name = "book"

Saving/updating is working, so each action creates some kind of snapshot. To get history of model:

reversion.get_for_object(model)

and my question is, how to create rest api for history?

I would be glad if one of you could share with experiences in this topic.

falsetru
  • 357,413
  • 63
  • 732
  • 636
ASmith78
  • 153
  • 8
  • If `reversion.get_for_object(model)` returns a list of querysets maybe you can do `queryset = reversion.get_for_object(Author)` – dan-klasson Jul 27 '13 at 09:03
  • I tried that, but this method required a single model object, not class. – ASmith78 Jul 27 '13 at 16:18
  • Check out the source code for [get_for_object()](https://github.com/etianen/django-reversion/blob/master/src/reversion/revisions.py#L515). It does return a list of querysets. What error did you get and what about if you do `queryset = reversion.get_for_object(Author.objects.get(id=1))`? – dan-klasson Jul 27 '13 at 19:33
  • When i try get_for_object for whole class it looks: `AttributeError: type object 'ModelBase' has no attribute '_meta'` Your second proposition works well so maybe this construction should i use in queryset. I guess, to set object id I can set using bundle? Or there is more correct way? – ASmith78 Jul 28 '13 at 06:08
  • Better to override [obj_get](https://django-tastypie.readthedocs.org/en/v0.9.12/resources.html?highlight=resources#id10). Please let me know if that works for you and I'll add an answer. – dan-klasson Jul 28 '13 at 06:12

0 Answers0