利用EnterpriseWizard的rest接口的非关系Django数据库后端。
django-ewiz的Python项目详细描述
Version: | 1.5.4 |
---|---|
Dependencies: | Python 3.4+, Django>=1.5, djangotoolbox>=1.6.2, requests>=2.2.0 |
Home page: | https://github.com/kavdev/django-ewiz |
Author: | Alex Kavanaugh <kavanaugh.development@outlook.com> |
License: | GNU LGPL (http://www.gnu.org/licenses/lgpl.html) |
注意:版本1.3+将与EnterpriseWizard反SQL块一起工作。为了实现这一点,正则表达式和不区分大小写的查询操作被删除。
安装
运行pip install django-ewiz
将django_ewiz添加到INSTALLED_APPS
INSTALLED_APPS=(...'django_ewiz',...)
用法
基本用法
在DATABASESsettings字典中,只需使用django\u ewiz作为引擎键。
'default':{'ENGINE':'django_ewiz','NAME':'',# The name of the knowlegebase'USER':'',# The name of the user'PASSWORD':'',# The user's password'HOST':'',# EnterpriseWizard's REST base url, generally 'www.example.com/ewws/'. Don't include the protocol string (e.g. 'http://').'PORT':'',# Either 80 or 443 (HTTP or HTTPS requests only)'NUM_CONNECTIONS':'',# Default: 1, Allows multiple concurrent connections to be used when retrieving multiple tickets in a query.},
就这样!执行的所有数据库操作都将被抽象,并且应该像通常的引擎一样工作(除非您希望执行的操作与下面的选项冲突)。
支持以下查询操作:
- iexact
- icontains
- 在
- gt
- GTE
- lt
- LTE
- istartswith
- IEndswith
- 范围
- 年份
- 为空
以下查询操作将转换为各自不区分大小写的形式:(版本1.3+)
- 精确
- 包含
- 开始时使用
- 结束符
不再支持以下查询操作:(版本1.3+)
- 正则表达式
- IRegex
注意:并非所有票据字段都可以通过rest更改。添加editable=False作为模型选项以删除数据库错误。
文件上传
django ewiz确实支持文件上载-只是不以直接的方式(二进制上载到文件字段不起作用[稍后将对抽象进行更多的研究])
要将字段标记为文件字段,请添加help_text='file'作为模型字段选项。由于尝试直接修改字段行不通,建议添加editable=False以避免混淆。
file_field=CharField(help_text='file',editable=False,db_column='attached_files')
要上载文件,请使用提供的ewizattacher类(from django_ewiz import EwizAttacher)和以下参数:
- 设置ict-包含ewiz连接设置的数据库字典。例如,settings.databases['default']
- model-应将文件上载到的模型实例(模型必须包含且仅包含一个文件字段)。例如models.accountrequest.objects.get(ticket\u id=1)
- 文件参考-一个python文件对象。如果文件来自Django表单,请通过request.files['form_field_name']获取它。file
- 文件名-所需的文件名。如果文件来自Django表单,则可以通过request.files['form\u field\u name']获取其名称。name
文件上载示例
forms.py
fromdjango.formsimportForm,FileFieldclassEwizUploadForm(Form):uploaded_file=FileField(required=True)
models.py
fromdjango.db.modelsimportModel,AutoField,CharFieldclassAccountRequest(Model):ticket_id=AutoField(primary_key=True,db_column='id')subject_username=CharField(help_text=':')# Use this field only in conjunction with EwizAttacher - do not attempt to directly populate itfile_field=CharField(help_text='file',editable=False,db_column='attached_files')classMeta:db_table=u'account_request'managed=Falseverbose_name=u'Account Request'
views.py
fromdjango.confimportsettingsfromdjango.views.generic.editimportFormViewfromdjango_ewizimportEwizAttacherfrom.formsimportEwizUploadFormfrom.modelsimportAccountRequestclassUploadDemoView(FormView):template_name="ewizdemo.html"form_class=EwizUploadFormdefform_valid(self,form):# Create a new account requestticket=AccountRequest(subject_username=self.request.user.username)ticket.save()# Grab the filefile_reference=self.request.FILES['uploaded_file'].file# Upload the fileEwizAttacher(settings_dict=settings.DATABASES['default'],model=ticket,file_reference=file_reference,file_name=self.request.user.username+u'.pdf').attach_file()