Created
December 12, 2010 15:40
-
-
Save miloshadzic/738120 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
class Book(models.Model): | |
isbn = models.IntegerField(max_length=13) | |
title = models.CharField(max_length=100) | |
pub_date = models.IntegerField(max_length=4, choices=YEARS) | |
authors = models.ManyToManyField(Author, related_name="books") | |
categories = models.ManyToManyField(Category) | |
def __unicode__(self): | |
return self.title | |
class BookOnLoan(models.Model): | |
class Meta: | |
verbose_name_plural = 'Loaned Books' | |
user = models.ForeignKey(User) | |
# I want to limit choices to only Books that haven't been loaned out yet | |
# I need Books that have date_returned == None | |
# My problem is that I don't know how to filter for that from Book objects | |
# Thanks for looking! | |
book = models.ForeignKey(Book, limit_choices_to = ()) | |
date_issued = models.DateField(auto_now_add=True) | |
date_due = models.DateField(default= date.today() + DAYS_ON_LOAN) | |
date_returned = models.DateField(blank=True, null=True) | |
def save(self, *args, **kwargs): | |
super(BookOnLoan, self).save(*args, **kwargs) | |
def __unicode__(self): | |
return self.book.__unicode__() + " / " + self.user.__unicode__() + " / " + str(self.date_due) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment