Skip to content

Commit 8475220

Browse files
committed
update dto and model
1 parent 3b6c0fa commit 8475220

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

django_petra/models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class TimeStampedModel(models.Model):
7-
created = models.DateTimeField(db_index=True, auto_now_add=True)
7+
created = models.DateTimeField(auto_now_add=True)
88
modified = models.DateTimeField(auto_now=True)
99

1010
class Meta:
@@ -14,8 +14,8 @@ class Meta:
1414
class Extensions(models.Model):
1515
""" Best practice for lookup field url instead pk or slug """
1616

17-
uuid = models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)
18-
created = models.DateTimeField(auto_now_add=True, db_index=True)
17+
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
18+
created = models.DateTimeField(auto_now_add=True)
1919
modified = models.DateTimeField(auto_now=True)
2020

2121
class Meta:

django_petra/petra_dto.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ def wrapper(self, request, *args, **kwargs):
2020
if form.is_valid():
2121
return view_func(self, request, form, *args, **kwargs)
2222

23-
raise ValidationError(form.errors)
23+
# Format the error response
24+
formatted_errors = {
25+
'success': False,
26+
'errors': {}
27+
}
28+
29+
for field, error_list in form.errors.items():
30+
# Convert to array format
31+
formatted_errors['errors'][field] = [
32+
f"The {field} {error_list[0]}" # Format error message
33+
]
34+
35+
raise ValidationError(formatted_errors)
2436
return wrapper
2537
return decorator
2638

0 commit comments

Comments
 (0)