Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

fix for RecursionError issue #9 #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_postgres_extensions/models/expressions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db.models.expressions import F as BaseF, Value as BaseValue, Func, Expression
from django.utils import six
import six
from django.contrib.postgres.fields.array import IndexTransform
from django.utils.functional import cached_property
from django.db.models.lookups import Transform
Expand Down
10 changes: 5 additions & 5 deletions django_postgres_extensions/models/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.postgres import fields
from django.contrib.postgres import fields as django_fields
from django.contrib.postgres.forms import SplitArrayField as SplitArrayFormField
from django.forms.fields import TypedMultipleChoiceField
from psycopg2.extras import Json
Expand All @@ -9,7 +9,7 @@
from django.core import exceptions


class ArrayField(fields.ArrayField):
class ArrayField(django_fields.ArrayField):

def __init__(self, base_field, form_size=None, **kwargs):
super(ArrayField, self).__init__(base_field, **kwargs)
Expand Down Expand Up @@ -38,7 +38,7 @@ def formfield(self, **kwargs):
if self.choices:
defaults['coerce'] = self.base_field.to_python
defaults.update(kwargs)
return super(fields.ArrayField, self).formfield(**defaults)
return super(django_fields.ArrayField, self).formfield(**defaults)
return super(ArrayField, self).formfield(**kwargs)

def validate(self, value, model_instance):
Expand Down Expand Up @@ -84,7 +84,7 @@ def deconstruct(self):
})
return name, path, args, kwargs

class HStoreField(fields.HStoreField):
class HStoreField(django_fields.HStoreField):

def __init__(self, fields=(), keys=(), max_value_length=25, require_all_fields=False, **kwargs):
super(HStoreField, self).__init__(**kwargs)
Expand Down Expand Up @@ -119,7 +119,7 @@ def formfield(self, **kwargs):
defaults = kwargs
return super(HStoreField, self).formfield(**defaults)

class JSONField(fields.JSONField):
class JSONField(django_fields.JSONField):

def __init__(self, fields=(), require_all_fields=False, **kwargs):
super(JSONField, self).__init__(**kwargs)
Expand Down
28 changes: 14 additions & 14 deletions django_postgres_extensions/models/fields/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db import models
from django.db.models.fields.related import RECURSIVE_RELATIONSHIP_CONSTANT, lazy_related_operation
from django.forms.models import ModelMultipleChoiceField
from django.utils import six
import six
from django.utils.encoding import force_text
from .related_lookups import RelatedArrayContains, RelatedArrayExact, RelatedArrayContainedBy, RelatedContainsItem, \
RelatedArrayOverlap, RelatedAnyGreaterThan, RelatedAnyLessThanOrEqual, RelatedAnyLessThan, RelatedAnyGreaterThanOrEqual
Expand All @@ -21,27 +21,27 @@ class ArrayManyToManyField(ArrayField, RelatedField):

rel_class = ArrayManyToManyRel

def __init__(self, to_model, base_field=None, size=None, related_name=None, symmetrical=None,
def __init__(self, to, base_field=None, size=None, related_name=None, symmetrical=None,
related_query_name=None, limit_choices_to=None, to_field=None, db_constraint=False, **kwargs):

try:
to = to_model._meta.model_name
to_str = to._meta.model_name
except AttributeError:
assert isinstance(to_model, six.string_types), (
assert isinstance(to, six.string_types), (
"%s(%r) is invalid. First parameter to ForeignKey must be "
"either a model, a model name, or the string %r" % (
self.__class__.__name__, to_model,
self.__class__.__name__, to,
RECURSIVE_RELATIONSHIP_CONSTANT,
)
)
to = str(to_model)
to_str = str(to)
else:
# For backwards compatibility purposes, we need to *try* and set
# the to_field during FK construction. It won't be guaranteed to
# be correct until contribute_to_class is called. Refs #12190.
to_field = to_field or (to_model._meta.pk and to_model._meta.pk.name)
to_field = to_field or (to._meta.pk and to._meta.pk.name)
if not base_field:
field = to_model._meta.get_field(to_field)
field = to._meta.get_field(to_field)
if not field.is_relation:
base_field_type = type(field)
internal_type = field.get_internal_type()
Expand All @@ -58,10 +58,10 @@ def __init__(self, to_model, base_field=None, size=None, related_name=None, symm
base_field = models.IntegerField()

if symmetrical is None:
symmetrical = (to == RECURSIVE_RELATIONSHIP_CONSTANT)
symmetrical = (to_str == RECURSIVE_RELATIONSHIP_CONSTANT)

kwargs['rel'] = self.rel_class(
self, to, to_field,
self, to_str, to_field,
related_name=related_name,
related_query_name=related_query_name,
limit_choices_to=limit_choices_to,
Expand All @@ -71,10 +71,10 @@ def __init__(self, to_model, base_field=None, size=None, related_name=None, symm

self.db_constraint = db_constraint

self.to = to
self.to = to_str

if 'default' not in kwargs.keys():
kwargs['default'] = []
kwargs['default'] = list
kwargs['blank'] = True

self.from_fields = ['self']
Expand All @@ -84,15 +84,15 @@ def __init__(self, to_model, base_field=None, size=None, related_name=None, symm

def deconstruct(self):
name, path, args, kwargs = super(ArrayManyToManyField, self).deconstruct()
args = (self.to,)
kwargs.update({
'to': self.to,
'base_field': self.base_field,
'size': self.size,
'related_name': self.remote_field.related_name,
'symmetrical': self.remote_field.symmetrical,
'related_query_name': self.remote_field.related_query_name,
'limit_choices_to': self.remote_field.limit_choices_to,
'to_field': self.remote_field.field,
'to_field': self.remote_field.field_name,
'db_constraint': self.db_constraint
})
return name, path, args, kwargs
Expand Down
2 changes: 1 addition & 1 deletion django_postgres_extensions/models/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db.models.expressions import Func, Expression
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.utils import six
import six
from .expressions import F, Value as V

class SimpleFunc(Func):
Expand Down
2 changes: 1 addition & 1 deletion django_postgres_extensions/models/sql/subqueries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db.models.sql.subqueries import UpdateQuery as BaseUpdateQuery
from django.utils import six
import six
from django.core.exceptions import FieldError

class UpdateQuery(BaseUpdateQuery):
Expand Down
2 changes: 1 addition & 1 deletion docs/arraym2m.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use this field, it is required to set ENABLE_ARRAY_M2M = True in settings.py
Then in models.py::

from django.db import models
from django_postgres_extensions.models.fields import ArrayManyToManyField
from django_postgres_extensions.models import ArrayManyToManyField

class Publication(models.Model):
title = models.CharField(max_length=30)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
django
django
six