Django DateField конфликтует с экземпляром datetime.date: AttributeError: объект 'Period' не имеет атрибута 'strftime'

Когда я пытаюсь создать новый экземпляр модели в функции, я получаю следующую ошибку:

TypeError: fromisoformat: аргумент должен быть str

Моим первым предположением был формат объекта даты, но я передаю правильный объект даты, который также имеет формат Django DateField?

# utils.py

from datetime import date

def create_payroll_run():

    # Query all active companies
    qs_companies = Company.objects.filter(is_active=True)

    # Get the 1st of the month for the payroll run to be created
    next_payroll_run = date.today().replace(day=1)

    # Get the period instance
    period = Period.objects.get(period=next_payroll_run)

    # Loop the companies
    for company in qs_companies:
        # Query all Payments of that company in that month
        qs_payments = Payment.objects.filter(offer__company=company).filter(month=period)
        print(qs_payments)

        # Create a payroll run instance
        payroll_run = Payroll.objects.create(
            company=company,
            month=period,
            amount=qs_payments.aggregate(Sum('amount')),
            line_items=qs_payments.count()
        )

        payroll_run.save()
        
    return payroll_run
# Models.py

class Payroll(models.Model):
    """
    A table to store monthly payroll run information of companies
    """
    # Relates to one company
    company = models.ForeignKey(Company, on_delete=models.CASCADE)

    month = models.DateField()
    amount = models.DecimalField(decimal_places=2, max_digits=10)
    line_items = models.PositiveIntegerField()


class Period(models.Model):
    """
    A table to store all periods, one period equals a specific month
    """
    period = models.DateField()

Full Traceback:

Вернуться на верх