Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import Q, F
from django.utils import timezone
from django.utils.translation import gettext_lazy as _


Expand All @@ -24,7 +25,7 @@ def __str__(self):


class Borrowing(models.Model):
borrow_date = models.DateField(auto_now_add=True)
borrow_date = models.DateField(default=timezone.now().date())
expected_return_date = models.DateField()
actual_return_date = models.DateField(null=True, blank=True)

Expand Down
17 changes: 2 additions & 15 deletions library/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,13 @@


class BookSerializer(serializers.ModelSerializer):
class Meta:
model = Book
fields = (
"id",
"title",
"author",
"cover",
"inventory",
"daily_fee",
)


class BookDetailSerializer(serializers.ModelSerializer):
class Meta:
model = Book
fields = ("id", "title", "author", "cover", "inventory", "daily_fee")


class BorrowingReadSerializer(serializers.ModelSerializer):
book = BookDetailSerializer(read_only=True)
book = BookSerializer(read_only=True)

class Meta:
model = Borrowing
Expand All @@ -45,7 +32,7 @@ class Meta:
read_only_fields = ("id",)

def validate_expected_return_date(self, value):
today = timezone.localdate()
today = timezone.now().date()
if value < today:
raise serializers.ValidationError(
"Expected return date cannot be " "earlier than today."
Expand Down
2 changes: 1 addition & 1 deletion library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def return_book(self, request, pk=None):
status=status.HTTP_400_BAD_REQUEST,
)

borrowing.actual_return_date = timezone.localdate()
borrowing.actual_return_date = timezone.now().date()
borrowing.save(update_fields=["actual_return_date"])

Book.objects.filter(pk=borrowing.book_id).update(
Expand Down