Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use field.foreign_related_fields if >= dj1.9 #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_any/__init__.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = (0, 2, 3, 'final', 0)
__version__ = (0, 2, 4, 'final', 0)
try:
from django_any.forms import any_form_field, any_form
from django_any.models import any_field, any_model
Expand Down
6 changes: 5 additions & 1 deletion django_any/contrib/default.py
Expand Up @@ -3,6 +3,7 @@
from django.db.models.fields import NOT_PROVIDED
from django.db.models.fields.related import RelatedField
from django_any.models import any_model
import django


def any_model_with_defaults(cls, **attrs):
Expand All @@ -15,7 +16,10 @@ def any_model_with_defaults(cls, **attrs):
# for stuff like default=datetime.now
default = default()
if isinstance(field, RelatedField):
Model = field.related_field.model
if django.VERSION >= (1, 9):
Model = field.foreign_related_fields[0].model
else:
Model = field.related_field.model
if not isinstance(default, Model):
try:
default = Model.objects.get(pk=default)
Expand Down