add artist when posting
[zzz-floof.git] / floof / model / search.py
1 from elixir import *
2 # from users import User
3
4 from floof.lib.search import do_search
5
6 class SavedSearch(Entity):
7 string = Field(Unicode) # I tried calling this query, but it broke elixir
8 author = ManyToOne('User')
9 fork = ManyToOne("SavedSearch")
10
11 def __unicode__(self):
12 return self.string
13
14 @property
15 def results(self):
16 return do_search(self.string)
17
18
19
20 class GalleryWidget(Entity):
21 page = ManyToOne('UserPage')
22 search = ManyToOne(SavedSearch)
23
24 # NOTE: no longer needed now that we have pages, I guess.
25 # displayer = ManyToOne('User') # determines whose page should it should show up on
26 # # Could be no-ones, if it's just a template.
27
28 # Needs some fields for position on your page
29
30 @property
31 def string(self):
32 return self.search
33
34 @string.setter
35 def string(self, value):
36 # TODO: should we delete the possibly orphaned saved search?
37 # if not self.displayer:
38 # # TODO: may have to refactor this into an init if the key ordering is inconvenienc
39 # raise "Oh no! This gallery needs a displayer to set on the saved search."
40
41 self.search = SavedSearch(author=getattr(self,"author",None), string=value)