trying out resource routing. Works decently. Added lots of notes.
[zzz-floof.git] / floof / model / search.py
1 from elixir import *
2 from users import User
3
4 class SavedSearch(Entity):
5 string = Field(Unicode) # I tried calling this query, but it broke elixir
6 author = ManyToOne(User)
7
8 def __unicode__(self):
9 return self.string
10
11
12 class GalleryWidget(Entity):
13 search = ManyToOne(SavedSearch)
14 displayer = ManyToOne(User) # determines whose page should it should show up on
15 # Could be no-ones, if it's just a template.
16
17 # Needs some fields for position on your page
18
19 @property
20 def query(self):
21 return self.search.query
22
23 @query.setter
24 def query(self, value):
25 # TODO: should we delete the possibly orphaned saved search?
26 if not self.displayer:
27 # TODO: may have to refactor this into an init if the key ordering is inconvenienc
28 raise "Oh no! This gallery needs a displayer to set on the saved search."
29
30 self.search = SavedSearch(author=self.displayer, query=value)