Change history in admin always includes TagFields as "changed"
cnschn opened this issue · 2 comments
To reproduce: Just run the application in example/
, add a Person
, change any field(s) in the admin and save.
No matter which fields actually changed, the history always includes the TagField
fields, the SingleTagField
appears to be unaffected.
Screenshot of the history page in the admin, after I added a person, changed the name twice and the title once :
This probably has something to do with the way the Django admin determines if a field has changed (I think there is a bit of back and forth between prepare_value
and to_python
involved, it's a little fiddly) interfering with what select2 does to the form fields.
The issue seems to be that the has_changed(initial, data)
method for TagField
gets called with initial: FakeQueryset
, but data: str
(from the form field). A very simple workaround is to override the has_changed
method for the TagField
to mangle the initial
parameter into the appropriate string, i.e.
def has_changed(self, initial, data):
if hasattr(initial, 'values_list'):
# tagulous passed its fake queryset, take out the actual value
initial = initial.values_list()[0]
return super().has_changed(initial, data)
I'm not sure, but this feels like some part of prepare_value
/to_python
is not entirely correct, so there should probably be a better way to fix this.
Thanks for investigating! I wouldn't be surprised it there was something in there that's not entirely correct, to get tagulous working everywhere there are a fair few hacks involved.
I'm hoping to get some time on this project again soon, I'll push this up the list.