Just Launched: You can now import projects and releases from Google Code onto SourceForge
We are excited to release new functionality to enable a 1-click import from Google Code onto the Allura platform on SourceForge. You can import tickets, wikis, source, releases, and more with a few simple steps. Read More
> class Product(SQLObject):
> productName = StringCol(alternateID = True)
> def _get_urlFilename(self):
> return self.productName + '.html'
> Now, how do I select a product from the database by
> urlFilename? I want something like:
> Product.select(Product.q.urlFilename == 'filename')
The select method makes some SQL and sends it to the database. Since your
property doesn't add anything to the database, the database will not know
anything about urlFilenames. If you were to ::
fooProduct = list(Product.select(Product.q.productName == 'foo'))
then fooProduct.urlFilename would then equal 'foo.html'; but only once the
data is gotten from the database and stuffed into a Product object can you
talk about urlFilenames.
Given this example, it seems easiest if you want to search by urlFilename to
first figure out the productName from it, then query on the productName. You
could go like so:
productName = StringCol(alternateID = True)
return self.productName + '.html'
def selectByUrlFilename(cls, filename):
productName = filename[0:-5]
return cls.select(cls.q.productName == productName)
selectByUrlFileName = classmethod(selectByUrlFilename)
fooProduct = Product.selectByUrlFilename('foo.html')
Then you're only storing 'foo' once in the database, so no coherency
problems. (selectByUrlFilename should check more things about the filename
before blindly hacking off the last five characters, but you get the idea.)
Thanks for your reply! I had not thought about using a class method, and
that makes a lot of sense of course.
> but only once the data is gotten from the database and stuffed into a
Product object can you talk about urlFilenames.
> Given this example, it seems easiest if you want to search by
urlFilename to first figure out the productName from > it, then query on the
productName. You could go like so:
I did think of something like this, but the problem is that in my current
scheme it is not possible to find out the productName from the urlFilename.
I want nice filenames with dashes, and productnames can have dashes too, so
I cannot just do a search and replace.
I guess this problem must be a common one, is there a 'best practice' to do