Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ilham Maulana
library-app-django
Commits
8d5dee33
Commit
8d5dee33
authored
Jul 31, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: due date validator
parent
8a40b2ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
16 deletions
+6
-16
0006_alter_bookloan_due_date.py
loans/migrations/0006_alter_bookloan_due_date.py
+4
-4
models.py
loans/models.py
+2
-2
validators.py
loans/validators.py
+0
-10
No files found.
loans/migrations/0006_alter_bookloan_due_date.py
View file @
8d5dee33
...
...
@@ -7,13 +7,13 @@ from django.db import migrations, models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'loans'
,
'0005_alter_bookloan_loan_date'
),
(
"loans"
,
"0005_alter_bookloan_loan_date"
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'bookloan'
,
name
=
'due_date'
,
field
=
models
.
DateTimeField
(
validators
=
[
loans
.
validators
.
validate_due_date
]
),
model_name
=
"bookloan"
,
name
=
"due_date"
,
field
=
models
.
DateTimeField
(),
),
]
loans/models.py
View file @
8d5dee33
...
...
@@ -2,14 +2,14 @@ from django.db import models
from
book.models
import
Book
from
users.models
import
Member
from
.validators
import
validate_
due_date
,
validate_
loan_date
from
.validators
import
validate_loan_date
class
BookLoan
(
models
.
Model
):
book
=
models
.
ForeignKey
(
Book
,
on_delete
=
models
.
CASCADE
)
member
=
models
.
ForeignKey
(
Member
,
on_delete
=
models
.
CASCADE
)
loan_date
=
models
.
DateTimeField
(
validators
=
[
validate_loan_date
])
due_date
=
models
.
DateTimeField
(
validators
=
[
validate_due_date
]
)
due_date
=
models
.
DateTimeField
()
return_date
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
updated_at
=
models
.
DateTimeField
(
auto_now
=
True
)
loans/validators.py
View file @
8d5dee33
...
...
@@ -11,13 +11,3 @@ def validate_loan_date(value):
_
(
"Loan date cannot be later than today"
),
params
=
{
"value"
:
value
},
)
def
validate_due_date
(
value
):
due_date
=
value
loan_date
=
timezone
.
now
()
if
due_date
<
loan_date
:
raise
ValidationError
(
_
(
"Due date cannot be less than loan date"
),
params
=
{
"value"
:
value
},
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment