开发者

Google app engine countrycode in key_name

开发者 https://www.devze.com 2022-12-24 09:32 出处:网络
I have a table with countrycodes, whats the best way to store the开发者_JS百科se 2 digit codes, just in a regular property or in the key_name property?

I have a table with countrycodes, whats the best way to store the开发者_JS百科se 2 digit codes, just in a regular property or in the key_name property?

I thought using key_name will produce faster performance?

Ton.


Whether or not you want to use key_name depends on how you want to use it. I'm not entirely certain how you want to use these country codes based on the information in your question. Let's say, however, that you want to be able to look up the full name of the country based on the two-letter code, for instance, to get "United States" from "us". In that case, you could have an entity like this:

class CountryName(db.Model):
    name = db.StringProperty()

    @classmethod
    def lookup_by_code(cls, code):
        country_name = ""
        country = cls.get_by_key_name(code)
        if country is not None:
            country_name = country.name

        return country_name

Now, this code is not complete; you'd need to populate the model with data, and this approach does not allow for reverse lookups -- getting the code when you have the country name, but this should give you an idea of how you might be able to use key_names. Doing it this way would be substantially faster then, say, having a model that contained both code and name as fields.

0

精彩评论

暂无评论...
验证码 换一张
取 消