Skip to content

Instantly share code, notes, and snippets.

@Eugeny
Created September 4, 2012 16:32
Show Gist options
  • Save Eugeny/3623175 to your computer and use it in GitHub Desktop.
Save Eugeny/3623175 to your computer and use it in GitHub Desktop.
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