Skip to content

Commit

Permalink
Merge pull request coagulant#59 from hovel/callable_default
Browse files Browse the repository at this point in the history
Call any callable default value in any_model_with_defaults
  • Loading branch information
GeyseR committed Sep 3, 2017
2 parents c9ba5f2 + 2a80411 commit ecf4284
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions django_any/contrib/default.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from inspect import isfunction, ismethod
from django.db.models.fields import NOT_PROVIDED
from django.db.models.fields.related import ForeignKey, OneToOneField

Expand All @@ -13,7 +12,7 @@ def any_model_with_defaults(cls, **attrs):
for field in cls._meta.fields:
default = field.default
if default is not NOT_PROVIDED:
if isfunction(default) or ismethod(default):
if callable(default):
# for stuff like default=datetime.now
default = default()
if isinstance(field, (ForeignKey, OneToOneField)):
Expand Down

0 comments on commit ecf4284

Please sign in to comment.