Created
March 21, 2019 14:12
-
-
Save keclements/548d3355fc11a73bd17186ee4ac2fe24 to your computer and use it in GitHub Desktop.
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
import uuid # Required for unique book instances | |
class BookInstance(models.Model): | |
"""Model representing a specific copy of a book (i.e. that can be borrowed from the library).""" | |
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular book across whole library') | |
book = models.ForeignKey('Book', on_delete=models.SET_NULL, null=True) | |
imprint = models.CharField(max_length=200) | |
due_back = models.DateField(null=True, blank=True) | |
LOAN_STATUS = ( | |
('m', 'Maintenance'), | |
('o', 'On loan'), | |
('a', 'Available'), | |
('r', 'Reserved'), | |
) | |
status = models.CharField( | |
max_length=1, | |
choices=LOAN_STATUS, | |
blank=True, | |
default='m', | |
help_text='Book availability', | |
) | |
class Meta: | |
ordering = ['due_back'] | |
def __str__(self): | |
"""String for representing the Model object.""" | |
return f'{self.id} ({self.book.title})' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment