@@ -456,7 +456,7 @@ If you want to track many to many relationships, you need to define them explici
456
456
.. code-block :: python
457
457
458
458
class Category (models .Model ):
459
- pass
459
+ name = models.CharField( max_length = 200 )
460
460
461
461
class Poll (models .Model ):
462
462
question = models.CharField(max_length = 200 )
@@ -474,19 +474,19 @@ You will see the many to many changes when diffing between two historical record
474
474
475
475
.. code-block :: python
476
476
477
- informal = Category(name = " informal questions" )
478
- official = Category(name = " official questions" )
477
+ informal = Category.objects.create (name = " informal questions" )
478
+ official = Category.objects.create (name = " official questions" )
479
479
p = Poll.objects.create(question = " what's up?" )
480
480
p.save()
481
481
p.categories.add(informal, official)
482
482
p.categories.remove(informal)
483
483
484
484
last_record = p.history.latest()
485
- previous_record = last_record.prev_record()
485
+ previous_record = last_record.prev_record
486
486
delta = last_record.diff_against(previous_record)
487
487
488
488
for change in delta.changes:
489
- print (" {} changed from {} to {} " )
489
+ print (" {} changed from {} to {} " .format(change.field, change.old, change.new) )
490
490
491
491
# Output:
492
492
# categories changed from [{'poll': 1, 'category': 1}, { 'poll': 1, 'category': 2}] to [{'poll': 1, 'category': 2}]
0 commit comments