~divmod-dev/divmod.org/1304710-storeless-adapter

« back to all changes in this revision

Viewing changes to Axiom/axiom/examples/bucket.py

  • Committer: glyph
  • Date: 2005-07-28 22:09:16 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:2
move this repository to a more official-looking URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from axiom import item, attributes
 
2
 
 
3
class Bucket(item.Item):
 
4
    typeName = 'bucket'
 
5
    schemaVersion = 1
 
6
 
 
7
    name = attributes.text()
 
8
 
 
9
    def getstuff(self):
 
10
        for food in self.store.query(FoodItem,
 
11
                                     FoodItem.bucket == self,
 
12
                                     sort=FoodItem.deliciousness.descending):
 
13
            food.extra.what()
 
14
 
 
15
 
 
16
class FoodItem(item.Item):
 
17
    typeName = 'food'
 
18
    schemaVersion = 1
 
19
 
 
20
    bucket = attributes.reference()
 
21
    extra = attributes.reference()
 
22
    deliciousness = attributes.integer(indexed=True)
 
23
 
 
24
class Chicken(item.Item):
 
25
    typeName = 'chicken'
 
26
    schemaVersion = 1
 
27
 
 
28
    epistemologicalBasisForCrossingTheRoad = attributes.text()
 
29
    def what(self):
 
30
        print 'chicken!'
 
31
 
 
32
class Biscuit(item.Item):
 
33
    typeName = 'biscuit'
 
34
    schemaVersion = 1
 
35
 
 
36
    fluffiness = attributes.integer()
 
37
    def what(self):
 
38
        print 'biscuits!'
 
39
 
 
40
 
 
41
from axiom.store import Store
 
42
 
 
43
s = Store()
 
44
 
 
45
u = Bucket(name=u'whatever', store=s)
 
46
c = Chicken(epistemologicalBasisForCrossingTheRoad=u'extropian', store=s)
 
47
b = Biscuit(fluffiness=100, store=s)
 
48
 
 
49
FoodItem(store=s, deliciousness=3, extra=c, bucket=u)
 
50
FoodItem(store=s, deliciousness=4, extra=b, bucket=u)
 
51
 
 
52
u.getstuff()