Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversion with django-taggit #76

Closed
chris-r opened this issue Aug 10, 2011 · 10 comments
Closed

Reversion with django-taggit #76

chris-r opened this issue Aug 10, 2011 · 10 comments

Comments

@chris-r
Copy link

chris-r commented Aug 10, 2011

I'm not entirely sure whether this is your issue or a problem with django-taggit, but I figured I'd post it here (I'm also new to GitHub, so I apologize if I'm doing something wrong).

(If you haven't used django-taggit: TaggedItem has a generic foreign key pointing to the tagged object and a foreign key to a Tag. Tags are basically just a slug. In the admin we see a text field that somehow gets converted into a bunch of TaggedItems when we save the instance.)

I'm trying to use reversion on a model with tags = TaggableManager(blank=True).

I've manually registered the Tag and TaggedItem tables using reversion.register(Tag) and reversion.register(TaggedItem). I registered my model using reversion.register(MyModel, follow=["tags"])

But in the admin, the Edit / History / Revert page always shows the tags of the newest version, no matter which datetime I click on in the history list.

The database table reversion_version seems to be OK. Taggit chooses to remove all tags and recreate relink them when you save in the admin, so if I add a tag to an object that has one tag I get the following rows in the revision table:

(I'm assuming mode 0 = add, mode 1 = update, mode 2 = remove)

  • taggeditem for old_tag removed
  • taggeditem for old_tag added
  • taggeditem for new_tag added
  • new_tag added
  • old_tag updated (I didn't actually change the tag itself, but I think this would cause problems.)
  • myobject updated

This seems good to me. I'm guessing it isn't actually a revision problem, but a VersionAdmin / TaggableManager issue. I don't understand Django well enough to really understand how TaggableManager affects the model or how VersionAdmin populates the admin form, so this was about as far as I could go.

@etianen
Copy link
Owner

etianen commented Sep 9, 2011

There might well be an issue between the TaggableManager and VersionAdmin. The VersionAdmin code is, sadly, rather arcane, since the standard ModelAdmin class doesn't really have the hooks needed to bolt on django-reversion elegantly.

If someone who knows something about django-taggit wants to take a look at this issue, please do!

@vad
Copy link
Contributor

vad commented Nov 23, 2011

+1 :)

@mitar
Copy link

mitar commented Feb 26, 2013

+1

2 similar comments
@ferrouswheel
Copy link

+1

@boylesnick
Copy link

+1

@etianen
Copy link
Owner

etianen commented Sep 3, 2013

I'm seeing a list of four enthusiastic django-reversion and django-taggit users above this comment. Any one of you could earn fame and glory by solving this issue!

@gilmrjc
Copy link

gilmrjc commented Jul 24, 2016

I don't understand this issue but in this part:

The database table reversion_version seems to be OK. Taggit chooses to remove all tags and recreate relink them when you save in the admin

This is not from taggit. Django forms save the model's data and after that it will save all the m2m data. This is the behavior of Django itself.

@murdav
Copy link

murdav commented Aug 19, 2016

Dear All,
Come to this discussion from jedie/django-reversion-compare#10.
But I'm not using it because it's still not compatible with django-reversion==2.0.X

My venv with python 3.5:
Django==1.9.7
django-reversion==2.0.6
django-taggit==0.20.2
django-taggit-serializer==0.1.5
*

I'm new to django-reversion, I'm trying to understand the app behavior when in the model we have
keywords = TaggableManager(_('Keywords'), blank=True, )

For example, in the Django admin while saving the model (without actually changing any field) and having an empty or not tag field django-reversion creates a Version each time I click on the save button with "comment": "Changed keywords.", but I didn't modify anything.

  [
    {
        "data": "my stufff",
        "revision": {
            "date_created": "2016-08-19T09:30:31.301565Z",
            "user": "myuser",
            "comment": "Changed keywords."
        }
    },  
    {
        "data": "my stufff",
        "revision": {
            "date_created": "2016-08-19T09:30:01.451687Z",
            "user": "myuser",
            "comment": "Changed keywords."
        }
    },  
    {
        "data": "my stufff",
        "revision": {
            "date_created": "2016-08-19T09:28:01.301027Z",
            "user": "myuser",
            "comment": "Changed keywords."
        }
    },
    {
        "data": "my stuff",
        "revision": {
            "date_created": "2016-08-19T08:14:55.619006Z",
            "user": "",
            "comment": "Initial revision."
        }
    }
]

Why do we have this behavior?

D

@etianen
Copy link
Owner

etianen commented Aug 22, 2016

The comment is generated by django.contrib.admin, not django-reversion. I don't know why it chooses to create that erroneous comment.

Saving the model will always save a revision, even if nothing has changed. That's expected behaviour. Anything else generates race conditions in the database, and incurs a performance overhead.

@etianen
Copy link
Owner

etianen commented Nov 28, 2016

Closing for lack of activity.

@etianen etianen closed this as completed Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants