pythononwheels / pow_devel

development repo for PyhtonOnWheels framework
www.pythononwheels.org
MIT License
75 stars 10 forks source link

Auto Default value for lists not working #30

Closed pythononwheels closed 6 years ago

pythononwheels commented 6 years ago

So lists need an explicit "default" : [] in the model definition:

schema = {
        'title':    { 'type': 'string', 'maxlength' : 35},
        'text' :    { 'type': 'string'},
        'tags' :    { 'type': 'list', "default" : [] },
        "votes" :   { "type" : "integer", "default" : 0 }   
}

see line:

'tags' : { 'type': 'list', "default" : [] },

pythononwheels commented 6 years ago

Works. Tested with tinydb.

a=Alist()

print(a) { 'created_at': datetime.datetime(2018, 8, 28, 14, 38, 57, 42390), 'id': '', 'last_updated': datetime.datetime(2018, 8, 28, 14, 38, 57, 42390), 'tags': [], 'text': '', 'title': '', 'votes': 0}

a.tags.append(1) print(a.tags) [1]