Package: dirty-models
Dirty ModelsDirty models for python 3Documentationhttp://dirty-models.readthedocs.io/FeaturesPython 3 package.Easy to create a model.Non destructive modifications.Non false positive modifications.Able to restore original data for each field or whole model.Access to original data.Read only fields.Alias for fields.Custom getters and setters for each fields.Automatic cast value.Easy import from/export to dict.Basic field type implemented.Multi type fields.Default values for each field or whole model.HashMap model. It could be used instead of DynamicModel.FastDynamicModel. It could be used instead of DynamicModel. Same behavior, better performance.Pickable models.Datetime fields can use any datetime format using parser and formatter functions.No database dependent.Auto documentation usingDirty Models Sphinx extension.Json encoder.Field access like dictionary but with wildcards.Opensource (BSD License)ChangelogVersion 0.12.4Make it compatible with Python 3.10.Version 0.12.3Fix HashMapsModel’s hardcode field type.Version 0.12.2Fix access to HashMapsModel’s field type when it is hardcoded in a class.Version 0.12.1Fix~dirty_models.fields.MultiFieldTypeon creation mode.Fix~dirty_models.utils.BaseModelFormatterIterto be aware about override access modes.Exposed all useful classes on package root.Version 0.12.0Addedaccess_modeproperty to fields.
It could be~dirty_models.base.AccessMode.READ_AND_WRITEin order to allow to read and write.~dirty_models.base.AccessMode.WRITABLE_ONLY_ON_CREATIONin order to set value only on creation.~dirty_models.base.AccessMode.READ_ONLYin order to prevent writing.
And~dirty_models.base.AccessMode.HIDDENin order to hide field.Old field propertyread_onlyis deprecated in favor ofaccess_modebut it can be used like until this version.Helper~dirty_models.base.Creatingto mark model as in creation mode.Added class method~dirty_models.models.BaseModel.create_new_modelbuild a model and insert data
in creation mode.Allowed to override field access model on inherited fields using~dirty_models.models.BaseModel.__override_field_access_modes__hashmap.Version 0.11.3Fix bug casting string negative float.Fix exception casting non valid values to enumerations.Addedtitleproperty to fields.Addedmetadataproperty to fields. It could be used to store anything.Improved model formatter.Version 0.11.2Fix bug #107.Added~dirty_models.utils.ModelIteratorclass in order to be able to iterate over model fields.fromdirty_models.utilsimportModelIteratorforfieldname,field_obj,valueinModelIterator(my_model):print('Field name:{}'.format(fieldname))print('Field alias:{}'.format(field_obj.alias))print('Field value:{}'.format(value))Some fixes about read only data.Version 0.11.1Distribution fixes.Version 0.11.0New field type~dirty_models.fields.BytesField.String to integer casting could use any format allowed by Python: HEX (0x23), OCT (0o43) or
no-meaning underscores (1_232_232, only since Python 3.6).Version 0.10.1Factory<dirty_models.utils>feature. It allows to define a factory as
default value in order to be executed each time model is instanced. (Issue #100)fromdirty_models.utilsimportfactoryfromdatetimeimportdatetimeclassModel(BaseModel):field_1=DateTimeField(default=factory(datetime.now))model=Model()print(model.field_1)# 2017-11-02 21:52:46.339040Makefile fixes.Python 3.6 is supported officially. It works since first day, but now tests run on Travis for Python 3.6.Version 0.10.0Pickable lists.Improved pickle performance.SettingNoneto a field remove content.More tests.Some code improvements.Version 0.9.2Fix timezone when convert timestamp to datetime.Version 0.9.1Fix installation.Version 0.9.0New EnumField.Fixes on setup.py.Fixes on requirements.Fixes on formatter iters.Fixes on code.Added__version__to main package file.Synchronized version between main packege file,setup.pyand docs.Export only modifications.Version 0.8.1Added __contains__ function to models and lists. It allows to useinoperator.Addeddefault_timezoneparameter to DateTimeFields and TimeFields. If value entered has no a timezone
defined, default one will be set.Addedforce_timezoneparameter to DateTimeFields in order to convert values to a specific timezone.More cleanups.Version 0.8.0Renamed internal fields. Now they use double score format__fieldname__.Raise a RunTimeError exception if two fields use same alias in a model.Fixed default docstrings.Cleanup default data. Only real name fields are allowed to use as key.Added~dirty_models.models.BaseModel.get_attrs_by_pathin order to get all values using path.Added~dirty_models.models.BaseModel.get_1st_attr_by_pathin order to get first value using path.Added option to access fields like in a dictionary, but using wildcards. Only for getters.
See:~dirty_models.models.BaseModel.get_1st_attr_by_path.Added some documentation.Version 0.7.2Fixed inherited structureAddedget_default_datamethod to models in order to retrieve default data.Version 0.7.1Solved problem formatting dynamic modelsAdded date, time and timedelta fields to dynamic models.Version 0.7.0Timedelta fieldGeneric formattersJson encoderimportjsonfromdatetimeimportdatetimefromdirty_modelsimportBaseModel,DatetimeFieldfromdirty_models.utilsimportJSONEncoderclassExampleModel(BaseModel):field_datetime=DatetimeField(parse_format="%Y-%m-%dT%H:%M:%S")model=ExampleModel(field_datetime=datetime.now())assertjson.dumps(model,cls=JSONEncoder)=='{"field_datetime": "2016-05-30T22:22:22"}'Auto camelCase fields metaclassVersion 0.6.3Documentation fixed.Allow import main members from root package.Version 0.6.2Improved datetime fields parser and formatter definitions. Now there are three ways to define them:Format string to use both parse and formatter:classExampleModel(BaseModel):datetime_field=DateTimeField(parse_format='%Y-%m-%dT%H:%M:%SZ')Define a format string or function for parse and format datetime:classExampleModel(BaseModel):datetime_field=DateTimeField(parse_format={'parser':callable_func,'formatter':'%Y-%m-%dT%H:%M:%SZ'})Use predefined format:DateTimeField.date_parsers={'iso8061':{'formatter':'%Y-%m-%dT%H:%M:%SZ','parser':iso8601.parse_date}}classExampleModel(BaseModel):datetime_field=DateTimeField(parse_format='iso8061')Version 0.6.1Improved model field autoreference.classExampleModel(BaseModel):model_field=ModelField()# Field with a ExampleModelarray_of_model=ArrayField(field_type=ModelField())# Array of ExampleModelsVersion 0.6.0Added default value for fields.classExampleModel(BaseModel):integer_field=IntegerField(default=1)model=ExampleModel()assertmodel.integer_fieldis1Added default values at model level. Inherit default values could be override on new model classes.classInheritExampleModel(ExampleModel):__default_data__={'integer_field':2}model=InheritExampleModel()assertmodel.integer_fieldis2Added multi type fields.classExampleModel(BaseModel):multi_field=MultiTypeField(field_types=[IntegerField(),StringField()])model=ExampleModel()model.multi_field=2assertmodel.multi_fieldis2model.multi_field='foo'assertmodel.multi_fieldis'foo'Version 0.5.2Fixed model structure.Makefile helpers.Version 0.5.1Added a easy way to get model structure. It will be used by autodoc libraries as sphinx or json-schema.Version 0.5.0Added autolist parameter to ArrayField. It allows to assign a single item to a list field,
so it will be converted to a list with this value.classExampleModel(BaseModel):array_field=ArrayField(field_type=StringField(),autolist=True)model=ExampleModel()model.array_field='foo'assertmodel.array_field[0]is'foo'Installation$pipinstalldirty-modelsIssuesGetter and setter feature needs refactor to be able to use as decorators.DynamicModel is too strange. I don’t trust in it. Try to use HashMapModel or FastDynamicModel.Basic usagefromdirty_models.modelsimportBaseModelfromdirty_models.fieldsimportStringField,IntegerFieldclassFooBarModel(BaseModel):foo=IntegerField()bar=StringField(name="real_bar")alias_field=IntegerField(alias=['alias1','alias2'])fb=FooBarModel()fb.foo=2assertfb.foois2fb.bar='wow'assertfb.baris'wow'assertfb.real_baris'wow'fb.alias_field=3assertfb.alias_fieldis3assertfb.alias1isfb.alias_fieldassertfb.alias2isfb.alias_fieldassertfb['alias_field']is3NoteMore examples and documentation onhttp://dirty-models.readthedocs.io/