manytomanyfield - django-reversion revert ManyToMany fields outside admin -


i using django-reversion in project. , works except 1 thing: can't previous versions of manytomany fields. in django admin works, not in code. previous version use following code:

vprod = version.objects.get_for_date(product, ondate).get_object_version().object

and works except m2m field 'product' object of product class,

class product(models.model):     name = models.charfield(max_length=255)     elements = models.manytomanyfield(sku)  class sku(models.model):     name = models.charfield(max_length=255, verbose_name="sku name") 

i can vprod.name , returns need, when try vprod.elements.all() returns list current (last) version, if number of elements changed.

if understand correctly, think should revision version; version contains data of object, revision contains versions multiple objects. have at:

some_version.revision.version_set.all()

concretely, think should use (untested):

[ v v in version.objects.get_for_date(product, ondate).revision.version_set.all() if version.content_type == contenttype.objects.get_for_model(sku) ]

note, btw, reversions should know should follow relationships. using low level api:

reversion.register(yourmodel, follow=["your_foreign_key_field"])


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -