Created
September 4, 2012 16:32
-
-
Save Eugeny/3623175 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BankUser (Model): | |
name = CharField(...) | |
login = CharField(...) | |
password = PasswordField(...) | |
@property | |
def overdrafted_accounts(self): | |
// SELECT * FROM db.bankaccount WHERE user__id=1 AND money<0 | |
return BankAccount.objects.filter(user=self, money__lt=0).all() | |
class BankAccount (Model): | |
user = ForeignKey(BankUser) | |
money = IntegerField(...) | |
----- | |
user = User.objects.get(login='vasya') // SELECT * FROM db.bankuser WHERE login='vasya' | |
accounts = user.overdrafted_accounts | |
// accounts = [BankAccount, BankAccount, BankAccount] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment