﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28301	Object history is not logged for many to many fields	Karolis Ryselis	nobody	"Consider this models.py:

{{{
from django.db import models


class Model1(models.Model):
    title = models.CharField(max_length=20)

    def __str__(self):
        return self.title


class Model2(models.Model):
    title = models.CharField(max_length=20)
    models1 = models.ManyToManyField(to=""Model1"")

    def __str__(self):
        return self.title
}}}

and this admin.py

{{{
from django.contrib import admin

from .models import Model1, Model2

admin.site.register(Model1)
admin.site.register(Model2)
}}}

My test scenario:
1. Add two `Model1` items via admin
2. Add one `Model2` item via admin, choose one instance of `Model1` for many-to-many field
3. Edit the `Model2` item via admin choosing both `Model1` instances for many-to-many field
4. Open history for `Model2` instance
5. ""No fields changed."" is in history even though we have changed one of the fields.

I guess that this could be caused by lazy evaluation of initial queryset.
Initial data is loaded from model instance using `model_to_dict` which calls `f.value_from_object` for each field. `ManyToManyField` implemention returns a queryset. It think it is only evaluated when object history messages are constructed, i.e., after object is saved to database, and queryset returns already saved values instead of initial values. Because of this, initial and saved data are always the same and this field never appears in `changed_data`.
I was able to reproduce this on 1.11.2.
"	Bug	closed	contrib.admin	1.11	Normal	duplicate			Unreviewed	0	0	0	0	0	0
