from .models import UsersActivitiesModel


def user_activity(request, model_name, model_id, activity, description):

    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')

    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')

    UsersActivitiesModel(model_name=model_name, model_id=model_id, activity=activity, description=description, created_by=request.user.username, user_ip=ip).save()