Skip to content

Instantly share code, notes, and snippets.

@keclements
Created March 21, 2019 14:12
Show Gist options
  • Save keclements/548d3355fc11a73bd17186ee4ac2fe24 to your computer and use it in GitHub Desktop.
Save keclements/548d3355fc11a73bd17186ee4ac2fe24 to your computer and use it in GitHub Desktop.
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