coleifer/peewee — Issue #14: New Model Defaults
Author: sant0sk1
Created: 2011-11-15 16:32:14+00:00
State: open

When you create a model that has default field values they get used when persisting to the db (and subsequently when being initialized from the db) but not when a new object is instantiated. A contrived example:

```python
class Post(peewee.Model):
comment_count = peewee.IntegerField(default=0)

post = Post()

post.comment_count # => None
post.save()
post.comment_count # => 0
```

I think it'd be more consistent if the defaults were applied to all objects of the class, not just ones that have been persisted or come from the database.

The change is quite simple, I believe. We just need to modify the `Model` class's `__init__` method like so:

```python
def __init__(self, *args, **kwargs):
self.get_field_dict()
for k, v in kwargs.items():
setattr(self, k, v)
```

If this is something you'd be willing to merge, I'll happily do the work and submit a pull request.

Let me know, thanks.