code: def create(self, request, project_id, *args, **kwargs):
      data = request.data.copy()
      data["from_user"] = request.user.id
      project = Project.objects.get(id=project_id)
      data["project"] = project.id
      serializer = self.serializer_class(data=data)
      serializer.is_valid()
  
      if serializer.is_valid():
          saved_instance = serializer.save()
          # Create the content for the email
          current_site = get_current_site(request)
          mail_subject = (
              "ModelChimp: You have been invited to join %s"
              % (project.name,)
          )
          message = render_to_string(
              "email/invitation_email.html",
              {
                  "domain": current_site,
                  "invite_id": urlsafe_base64_encode(
                      force_bytes(saved_instance.id)
                  ),
                  "project_name": project.name,
              },
          )
          to_email = serializer.validated_data["to_email"]
          email = EmailMessage(mail_subject, message, to=[to_email])
          try:
              email.send()
          except Exception as e:
              saved_instance.delete()
  
          return Response({}, status=status.HTTP_201_CREATED)
  
      return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
  
file_path: modelchimp/modelchimp/views/api/invitation.py
imports: from django.contrib.sites.shortcuts import get_current_site
  from django.utils.encoding import force_bytes, force_text
  from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
  from django.template.loader import render_to_string
  from django.core.mail import EmailMessage
  from modelchimp.models.user import User
  from modelchimp.models.project import Project
  from modelchimp.models.invitation import Invitation
  from modelchimp.models.membership import Membership
  from modelchimp.serializers.invitation import InvitationSerializer
  from rest_framework import status, generics
  from rest_framework.response import Response
  from modelchimp.api_permissions import HasProjectMembership
  from rest_framework.permissions import IsAuthenticated
label_desc: Use image node_id 1 for calling the InviteAPI obj's underlying member method code with example usage: obj.create(request, project_id) and returns: Response, Response