Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update models.py - Referencing the User model #127

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __str__(self):
import uuid # Required for unique book instances
from datetime import date

from django.contrib.auth.models import User # Required to assign User as a borrower
from django.conf import settings # Required to assign User as a borrower


class BookInstance(models.Model):
Expand All @@ -74,7 +74,7 @@ class BookInstance(models.Model):
book = models.ForeignKey('Book', on_delete=models.RESTRICT, null=True)
imprint = models.CharField(max_length=200)
due_back = models.DateField(null=True, blank=True)
borrower = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
borrower = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True)

@property
def is_overdue(self):
Expand Down
3 changes: 3 additions & 0 deletions catalog/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def test_lists_all_authors(self):
from catalog.models import BookInstance, Book, Genre, Language
from django.contrib.auth.models import User # Required to assign User as a borrower

# Get user model from settings
hamishwillee marked this conversation as resolved.
Show resolved Hide resolved
from django.contrib.auth import get_user_model
User = get_user_model()

class LoanedBookInstancesByUserListViewTest(TestCase):

Expand Down