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