我正在研究一种非常简单的“查询语法”,供具有适当技术技能的人员使用(即,本身不是编码人员,但可以触及该主题)
他们将在表格上输入的典型示例是:
address like street
AND
vote = True
AND
(
(
age>=25
AND
gender = M
)
OR
(
age between [20,30]
AND
gender = F
)
OR
(
age >= 70
AND
eyes != blue
)
)
Run Code Online (Sandbox Code Playgroud)
用
我正在使用pyparsing(好吧,无论如何尝试)并达到以下目标:
from pyparsing import *
OPERATORS = [
'<',
'<=',
'>',
'>=',
'=',
'!=',
'like'
'regexp',
'between'
]
unicode_printables = u''.join(unichr(c) for c in xrange(65536)
if not unichr(c).isspace())
# user_input is the text sent by …Run Code Online (Sandbox Code Playgroud) 使用wagtail 2.1,django 2.0.3,python 3.6.4
我有以下的(简化)自定义图像模型,挂PhotoType,并PhotoPlate通过M2M关系:
from wagtail.images.models import AbstractImage
from modelcluster.fields import ParentalManyToManyField
from modelcluster.models import ClusterableModel
class PhotoType(models.Model):
title = models.CharField(verbose_name='Title', max_length=255, blank=False, null=False, default=None)
class PhotoPlate(models.Model):
plate= models.CharField(verbose_name='Title', max_length=255, blank=False, null=False, default=None)
class Photo(AbstractImage):
type = ParentalManyToManyField(PhotoType, help_text="Several are allowed.", blank=True)
plate = ParentalManyToManyField(PhotoPlate, help_text="Several are allowed.", blank=True)
class Meta:
verbose_name = 'Photo'
verbose_name_plural = 'Photos'
Run Code Online (Sandbox Code Playgroud)
在PhotoType和PhotoPlate模式是通过引用modeladmin_register(PhotoTypeModelAdmin),并 modeladmin_register(PhotoPlateModelAdmin)在本地wagtail_hooks.py文件。
遵循文档后一切正常。
除了一件事:无论为两个字段type和呈现的多项选择下拉列表中选择了多少项,都plate …