我有以下信号:
@receiver(post_save, sender=Document)
def handle_added_or_edited_element(sender, instance, **kwargs):
'''
This signal is used to compare the original and the current instance of the object being saved.
If at least one field has changed, a row is inserted in the revision history of the related srd_revision
'''
for field in sender._meta.get_fields():
if field.name in ['srd_revision', 'srdrevision', 'srd_rev']:
print(instance._meta.get_fields()[0])
if not isinstance(field, (models.ManyToOneRel, models.ManyToManyRel)):
if instance._get_field_value_map(instance._meta)[field.name].value != instance.__original_instance._get_field_value_map(instance._meta)[field.name].value:
chapter, message = RevisionHistory().get_document_messages(instance=instance, created=False, updated_field=field.name)
SrdRevisionHistory(chapter=chapter, title=message)
这两行:
if field.name in ['srd_revision', 'srdrevision', 'srd_rev']:
print(instance._meta.get_fields()[0])
给我一个ManyToManyRel:<ManyToManyRel: srdapp.srdrevision>
我想访问与Document
对象相关的srdrevision
对象中的id
.