Ошибка: Неверный формат даты/времени - Значение «0000-00-00 00:00:00.000000» соответствует формату, но недействительно как дата/время в проверке Django
> Ваш class EnrollmentModel(models.Model): Semesters=[ (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five'), (6, 'Six'), (7, 'Seven'), (8, 'Восемь'), ]
payment_type=(
('Marchent','Marchent'),
('Bkash','Bkash'),
('Rocket','Rocket'),
('Nagad','Nagad'),
('Cash Hand','Cash Hand'),
('Apps','Apps'),
('Upay','Upay'),
)
enroll_status=(
('Pending','Pending'),
('Due','Due'),
('Due-Pending','Due-Pending'),
('Complete','Complete'),
('Refunded','Refunded'),
('Due-Paid','Due-Paid'),
('Customized-Paid','Customized-Paid'),
)
layer=(
('Full','Full'),
('Department','Department'),
('Non-Department','Non-Department'),
)
softmax_student_id = models.CharField(max_length=50, unique=True,null=True, blank=True)
student = models.ForeignKey(StudentModel, related_name='student_enroll', on_delete=models.CASCADE,null=True,db_index=True)
package = models.ForeignKey(PackageModel, related_name='package_enroll', on_delete=models.CASCADE,null=True,db_index=True)
plan = models.ForeignKey(PlanModel, related_name='plans', on_delete=models.CASCADE,null=True,db_index=True)
category = models.ForeignKey(CategoryModel, related_name='categories', on_delete=models.CASCADE,null=True,db_index=True)
employee = models.ForeignKey(User, related_name='employee_enroll', on_delete=models.CASCADE, null=True,db_index=True)
subject=models.ManyToManyField(DepartmentSubjectModel, related_name='dept_subject',blank=True)
semester = models.IntegerField(choices=Semesters, null=True, blank=True)
course_fee = models.IntegerField(default=0,null=True,blank=True)
payable_fee = models.IntegerField(default=0,blank=True,null=True)
due_payment_date = models.DateField(default=current_date, null=True, blank=True)
extra_amount = models.IntegerField(default=0,null=True, blank=True)
sponsored_amount = models.IntegerField(default=0,null=False, blank=True)
initial_paid = models.IntegerField(default=0,null=False, blank=True)
payment_type = models.CharField(max_length=100, choices=payment_type, blank=True, null=True)
payment_number = models.CharField(max_length=100, null=True, blank=True)
is_due_enrollment = models.BooleanField(default=False)
invoice_number = models.CharField(max_length=100, null=True, blank=True)
course_note = models.TextField(max_length=500, null=True, blank=True)
status = models.CharField(max_length=20, choices=enroll_status, default='Pending')
package_layer=models.CharField(max_length=100,null=True,blank=True,choices=layer)
created_at = models.DateTimeField( default=timezone.now,db_index=True,null=True, blank=True)
updated_at=models.DateTimeField(auto_now=True)
is_old_student= models.BooleanField( default=False, null=True, blank=True)
is_message_send= models.BooleanField( default=False,null=True, blank=True)
is_service_satisfied= models.BooleanField( default=False,null=True, blank=True)
class Update_EnrollmentSerializer(serializers.ModelSerializer): # package = serializers.PrimaryKeyRelatedField(queryset=PackageModel.objects.all(), required=True) # student = serializers.PrimaryKeyRelatedField(queryset=StudentModel.objects.all(), required=True) предмет = serializers.PrimaryKeyRelatedField(queryset=DepartmentSubjectModel.objects.all(), required=False, many=True)
created_at = serializers.DateTimeField(
input_formats=[
'%Y-%m-%dT%H:%M:%S',
'%Y-%m-%dT%H:%M:%S.%f',
'%Y-%m-%d %H:%M:%S',
'%Y-%m-%d',
'%Y-%m-%d %I:%M %p' # Handle "12:00 AM" case
],
required=False
)
class Meta:
model = EnrollmentModel
fields = '__all__'
# exclude=['created_at']
def update(self, instance, validated_data):
try:
subjects = validated_data.pop('subject',None)
created_at = validated_data.get('created_at', instance.created_at)
# Update created_at field if provided
if created_at:
instance.created_at = created_at
# Update other fields
for attr, value in validated_data.items():
setattr(instance, attr, value)
instance.save()
# Update Many-to-Many field (subjects)
if subjects is not None:
instance.subject.set(subjects)
except serializers.ValidationError as e:
# Handle validation errors specifically
raise serializers.ValidationError({"detail": str(e)})
except KeyError as e:
# Handle KeyError (missing field)
raise serializers.ValidationError({"detail": f"Missing field: {str(e)}"})
except Exception as e:
# Handle all other exceptions and log them
raise serializers.ValidationError({"detail": f"An unexpected error occurred: {str(e)}"})
return instance
def to_representation(self, instance):
representation = super().to_representation(instance)
representation['student'] = instance.student.id if instance.student else None
representation['created_at'] = instance.created_at.strftime('%Y-%m-%d %H:%M:%S') if instance.created_at else timezone.now()
return representation
text`
Ошибка: { «detail": «Произошла непредвиденная ошибка: [''0000-00-00 00:00:00.000000'' значение имеет правильный формат (YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]), но это недопустимая дата/время.'']» }
В базе данных, created_at='2024-10-28 00:00:00.000000', я не понимаю, почему возникает эта ошибка. пожалуйста, помогите