django的附加字段。
django-strawberr的Python项目详细描述
django的附加字段。
先决条件
- Django 1.8、1.9、1.10、1.11和2.0。
- Python2.7,3.6
文档
文档可在Read the Docs上找到。
主要功能和亮点
- MD5字段。
安装
从pypi安装最新稳定版本:
pip install django-strawberry
或github的最新稳定版本:
pip install https://github.com/barseghyanartur/django-strawberry/archive/stable.tar.gz
或BitBucket的最新稳定版本:
pip install https://bitbucket.org/barseghyanartur/django-strawberry/get/stable.tar.gz
用法
md5字段
如果希望从同一字段的另一个字段填充md5字段 模型。
例1
myapp/models.py
fromdjango.dbimportmodelsfromstrawberry.fieldsimportMD5FieldclassMyModel(models.Model):title=models.CharField(max_length=255)title_hash=MD5Field(populate_from='title',null=True,blank=True)def__str__(self):returnself.title
myapp/example.py
frommyapp.modelsimportMyModelmymodel=MyModel.objects.create(title="Lorem7")print(mymodel.title_hash)'d48a712e77902d0558a3721d9a4740c9'
例2
propulate参数也可以是一个可调用的 作为参数的模型实例。因此,示例与第一个相同 将是:
myapp/models.py
fromdjango.dbimportmodelsfromstrawberry.fieldsimportMD5Fielddefstrip_title(instance):returninstance.title.strip()classMyModel(models.Model):title=models.CharField(max_length=255)title_hash=MD5Field(populate_from=strip_title,null=True,blank=True,)def__str__(self):returnself.title
myapp/example.py
frommyapp.modelsimportMyModelmymodel=MyModel.objects.create(title=" Lorem7 ")print(mymodel.title_hash)'d48a712e77902d0558a3721d9a4740c9'
测试
这个项目被测试所覆盖。
要使用所有受支持的python/django版本进行测试,请键入:
tox
要针对特定环境进行测试,请键入:
tox -e py36-django110
要测试您的工作环境,请键入:
./runtests.py
要在工作环境中运行单个测试,请键入:
./runtests.py src/strawberry/tests/test_fields.py
或:
./manage.py test strawberry.tests.test_fields
假设您已经安装了所有需求。如果不是,首先 安装测试要求:
pip install -r examples/requirements/test.txt
编写文档
保持以下层次结构。
===== title ===== header ====== sub-header ---------- sub-sub-header ~~~~~~~~~~~~~~ sub-sub-sub-header ^^^^^^^^^^^^^^^^^^ sub-sub-sub-sub-header ++++++++++++++++++++++ sub-sub-sub-sub-sub-header **************************
许可证
gpl 2.0/lgpl 2.1
支架
如有任何问题,请通过Author部分中提供的电子邮件与我联系。