Django add pdf to a request value

in the following request I receive a total of 10 pdfs which I must combine in one document once this is done I have to upload it to the client model which stores the files in aws s3, once I pass the file with all the pdfs together it gives me the following error

    "error": true,
    "message": {
        "documents": [
            "The submitted data was not a file. Check the encoding type on the form."

this is mi code

 merger = PdfFileMerger()
                    for x in request.FILES:
                    merger.write(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'media/' + str( + '.pdf'))
                    pdf = open(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'media/' + str( + '.pdf'), 'rb')
                    # set the client Data
                    clientData = {
                        'first_name':['first_name'] if 'first_name' in else None,
                        'last_name':['last_name'] if 'last_name' in else None,
                        'social_reason':['social_reason'] if 'social_reason' in else None,
                        'documents': pdf,
                        'status': 0,
                    # Create a new client
                    client = ClientSerializer(data=clientData)

this is my model

from django.db import models

# Relations
from apps.misc.models import City, TypeIdentity, TypeCLient, CIIU
from import Broker
from apps.authentication.api.models.user.index import User

class Client(models.Model):
    id              = models.CharField(max_length=255, unique=True,primary_key=True, editable=False)
    type_client     = models.ForeignKey(TypeCLient, on_delete=models.CASCADE, blank=True)
    type_identity   = models.ForeignKey(TypeIdentity, on_delete=models.CASCADE, blank=True)
    document_number = models.CharField(max_length=255, blank=True, unique=True)
    first_name      = models.CharField(max_length=255, blank=True, null=True)
    last_name       = models.CharField(max_length=255, blank=True, null=True)
    social_reason   = models.CharField(max_length=255, blank=True, null=True)
    city            = models.ForeignKey(City, on_delete=models.CASCADE, blank=True)
    address         = models.CharField(max_length=255, blank=True)
    email           = models.CharField(max_length=255, blank=True, unique=True)
    phone_number    = models.CharField(max_length=255, blank=True, unique=True)
    ciiu            = models.ForeignKey(CIIU, on_delete=models.CASCADE, blank=True)
    broker          = models.ForeignKey(Broker, on_delete=models.CASCADE, blank=True)
    user            = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
    documents       = models.FileField(upload_to='documents/')
    income          = models.SmallIntegerField(blank=True, default=0)
    entered_by      = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='entered_by')
    state           = models.BooleanField(default=False)
    created_at      = models.DateTimeField(auto_now_add=True)
    updated_at      = models.DateTimeField(null=True, default=None)

    class Meta:
        db_table = 'clients'
        verbose_name = 'clients'
        verbose_name_plural = 'clients'
        ordering = ['created_at']

as you can see in the documents property of the clientData dict I assign the combined pdf previously, is there any way to solve this?

Back to Top