from django.forms.models import model_to_dict
from authentication.models import ActivityLog

def create_activity_log(user, instance, action, old_data=None, new_data=None):
    ActivityLog.objects.create(
        user=user,
        action=action,
        model_name=instance.__class__.__name__,
        instance_id=instance.id,
        instance_str=str(instance),
        old_data=old_data,
        new_data=new_data
    )