具有django的flow-in-choices值的简单库
django_choices_flow的Python项目详细描述
具有简单流程和规则的元选择
用法
fromdjango.dbimportmodelsfromdjango_choices_flowimportChoicesfromdjango_choices_flow.modelsimportFlowIntegerFieldclassMyChoices(Choices):NEW=1,'New content'# 'New content' is the display textWAIT=2,'Wait'CANCELED=-1,'Canceled'ERROR=-2,'Error'INVOICED=3,'Invoiced'# set transaction rulesNEW_RULES=[NEW,INVOICED,CANCELED,ERROR]WAIT_RULES=[CANCELED,ERROR,INVOICED]INVOICED_RULES=[CANCELED]classInvoces(models.Model):""" To use only choices """number=models.IntegerField()status=models.IntegerField(choices=MyChoices,default=MyChoices.NEW)def__unicode__(self):returnself.numberclassFlowInvoice(models.Model):""" To validate flow in choices """number=models.IntegerField()status=FlowIntegerField(choices=MyChoices,default=MyChoices.NEW)def__unicode__(self):returnself.number
外壳
>>>flow=FlowInvoice.objects.create(number=1234)>>>flow.status1>>>flow.status=MyChoices.INVOICED>>>flow.full_clean()>>>flow.save()>>>flow.status3>>>flow.status=MyChoices.WAIT>>>flow.full_clean()ValidationError:{'status':[u'Invalid choice: Wait']}
显影剂
# download code git clone git@github.com:valdergallo/django-choices-flow.git # install developer packages make # check coverage make coverage # test project make test#clean extra content make clean #send package make send_package #test py2 and py3 tox
License type: FREEBSD South: Support migrations Python: python 2.7 and python 3.3 Version: 0.9.2 Tested in Django: 1.2.x; 1.3.x; 1.4.x; 1.5.x; 1.6.x; 1.7.x