This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ideas/fields//models: introduce CustomIntegerField that raises valida…
…tion error for decimals with only zeros and use that in models
- Loading branch information
1 parent
a69db99
commit 037e7c9
Showing
3 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import re | ||
|
||
from django.db import models | ||
from django.forms import fields | ||
|
||
|
||
class CustomIntegerField(models.IntegerField): | ||
|
||
def formfield(self, **kwargs): | ||
return super().formfield(**{ | ||
'form_class': CustomIntegerFormField, | ||
**kwargs, | ||
}) | ||
|
||
|
||
class CustomIntegerFormField(fields.IntegerField): | ||
""" | ||
re_decimal is a regex that is sliced from the entered values, the original | ||
regex (zeros after a decimal point) is overwritten here, in order to raise | ||
a validation error for decimal values with only zeros after decimal | ||
""" | ||
re_decimal = re.compile(r'') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters