code: def _create_sg_attachment(self, django_attch):
          
  
          def set_prop(attachment, prop_name, value):
              if SENDGRID_VERSION < '6':
                  setattr(attachment, prop_name, value)
              else:
                  if prop_name == "filename":
                      prop_name = "name"
                  setattr(attachment, 'file_{}'.format(prop_name), value)
  
          sg_attch = Attachment()
  
          if isinstance(django_attch, MIMEBase):
              filename = django_attch.get_filename()
              if not filename:
                  ext = mimetypes.guess_extension(django_attch.get_content_type())
                  filename = "part-{0}{1}".format(uuid.uuid4().hex, ext)
              set_prop(sg_attch, "filename", filename)
              # todo: Read content if stream?
              set_prop(sg_attch, "content", django_attch.get_payload().replace("\n", ""))
              set_prop(sg_attch, "type", django_attch.get_content_type())
              content_id = django_attch.get("Content-ID")
              if content_id:
                  # Strip brackets since sendgrid's api adds them
                  if content_id.startswith("<") and content_id.endswith(">"):
                      content_id = content_id[1:-1]
                  # These 2 properties did not change in v6, so we set them the usual way
                  sg_attch.content_id = content_id
                  sg_attch.disposition = "inline"
  
          else:
              filename, content, mimetype = django_attch
  
              set_prop(sg_attch, "filename", filename)
              # Convert content from chars to bytes, in both Python 2 and 3.
              # todo: Read content if stream?
              if isinstance(content, str):
                  content = content.encode('utf-8')
              set_prop(sg_attch, "content", base64.b64encode(content).decode())
              set_prop(sg_attch, "type", mimetype)
  
          return sg_attch
docs: Handles the conversion between a django attachment object and a sendgrid attachment object.
          Due to differences between sendgrid's API versions, use this method when constructing attachments to ensure
          that attachments get properly instantiated.