相关疑难解决方法(0)

Django LowerCaseCharField

我们实现了LowerCaseCharField.我们很乐意听到更好的实施建议.

from django.db.models.fields import CharField

class LowerCaseCharField(CharField):
    """
    Defines a charfield which automatically converts all inputs to
    lowercase and saves.
    """

    def pre_save(self, model_instance, add):
        """
        Converts the string to lowercase before saving.
        """
        current_value = getattr(model_instance, self.attname)
        setattr(model_instance, self.attname, current_value.lower())
        return getattr(model_instance, self.attname)
Run Code Online (Sandbox Code Playgroud)

事实上我们喜欢的是:

> modelinstance.field_name="TEST"
> print modelinstance.field_name
'test'
Run Code Online (Sandbox Code Playgroud)

当前实现仅在保存时转换为小写.

python django lowercase

12
推荐指数
1
解决办法
6483
查看次数

使用纯&pythonic库将Unicode/UTF-8字符串转换为大写/小写字母

我使用谷歌应用程序引擎,不能使用任何C/C++扩展,只有纯和pythonic库来转换Unicode/UTF-8字符串到大/小写.str.lower()和string.lowercase()没有.

python google-app-engine case-conversion

11
推荐指数
1
解决办法
1万
查看次数