Giter Club home page Giter Club logo

django-json-field's People

Contributors

derek-schaefer avatar fladi avatar fletom avatar matklad avatar millar avatar somenick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-json-field's Issues

Django 1.7 compatibility

Not present in: commit 462edd22e5577ff9ee6477f7572b571700d1a2aa

I noticed this issue starting with: commit b787ef2dbff957c5b5a64be13f01f985d17ff05b
It might of been introduced in between those 2 commits. Please note that this 2 commits are for Django and not django-json-field.

Error bellow:

Internal Server Error: /phpanel/library/47/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/core/handlers/base.py", line 113, in get_response
response = wrapped_callback(request, _callback_args, *_callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 550, in wrapper
return self.admin_site.admin_view(view)(_args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/utils/decorators.py", line 105, in _wrapped_view
response = view_func(request, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/views/decorators/cache.py", line 52, in _wrapped_view_func
response = view_func(request, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/sites.py", line 202, in inner
return view(request, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 1420, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/utils/decorators.py", line 29, in _wrapper
return bound_func(_args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/utils/decorators.py", line 105, in _wrapped_view
response = view_func(request, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/utils/decorators.py", line 25, in bound_func
return func.get(self, type(self))(_args2, *_kwargs2)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/db/transaction.py", line 362, in inner
return func(_args, _kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 1356, in changeform_view
ModelForm = self.get_form(request, obj)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 609, in get_form
fields = flatten_fieldsets(self.get_fieldsets(request, obj))
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 347, in get_fieldsets
return [(None, {'fields': self.get_fields(request, obj)})]
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 598, in get_fields
form = self.get_form(request, obj, fields=None)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 634, in get_form
return modelform_factory(self.model, **defaults)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/forms/models.py", line 541, in modelform_factory
return type(form)(class_name, (form,), form_class_attrs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/forms/models.py", line 284, in new
opts.help_texts, opts.error_messages)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/forms/models.py", line 214, in fields_for_model
formfield = formfield_callback(f, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/contrib/admin/options.py", line 211, in formfield_for_dbfield
return db_field.formfield(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/json_field/fields.py", line 197, in formfield
return super(JSONField, self).formfield(**defaults)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/db/models/fields/init.py", line 1859, in formfield
return super(TextField, self).formfield(**defaults)
File "/usr/local/lib/python2.7/dist-packages/Django-1.7a2-py2.7.egg/django/db/models/fields/init.py", line 836, in formfield
return form_class(
_defaults)
File "/usr/local/lib/python2.7/dist-packages/json_field/forms.py", line 17, in init
super(JSONFormField, self).init(_args, **kwargs)
TypeError: init() got an unexpected keyword argument 'max_length'

JSONField breaks with model_to_dict

Hi!

I've been using a JSONField implementation I found floating around, but it's not as good as this project.

The one bug is, though, when I use django.forms.models.model_to_dict.

I'm confused about value_for_object here, because it returns the json representation,
while surely it could return the decoded json object?

My suggested fix would be to remove the method; the default superclass functionality seems good.
Or what do you think?

Decimal rounding

Hello,
i was comparing your django-json-field with django-jsonfield and the one included in django-extensions, and your is the best for my needs (write a real generic value... not a dict or list of generic values).

but running you test cases, i noticed that test_decimal() FAIL, reporting:

self.assertEqual(Decimal(1.24), self.json_model.objects.get(pk=t1.pk).json)
AssertionError: Decimal('1.2399999999999999911182158029987476766109466552734375') != u'1.2399999999999999911182158029987476766109466552734375'

what we can do for that?

Django 1.9 compatibility

Package will not work in Django 1.9 due to deprecated import in forms:

`django_json_field-0.5.7-py2.7.egg/json_field/forms.py:5: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.``

There is no necessary to import django.forms.util(s), because you're using it to raise ValidationError. Just import forms and change util.ValidationError to forms.ValidationError, or import ValidationError from django.core.exceptions.

ImportError: cannot import name JSONField

I haven't managed to install the package.

#settings.py
INSTALLED_APPS = (
...
    'json_field',
...
)

#models.py
from json_field import JSONField

from django.db import models

...

class Human(models.Model):
    phone_numbers = JSONField()

and when doing south migration:

  File "<...>/models.py", line 2, in <module>
    from json_field import JSONField
ImportError: cannot import name JSONField

I tried Django shell

(test)Dae-MacPro:test Dae$ python manage.py shell
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from json_field import JSONField
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: cannot import name JSONField

I'm using Django 1.4. I tried installing from repo and pip, no difference.

What might be the problem?

Thanks

Json field validation?

I was thinking about adding validation to the form field using jsonschema before saving it to the database. Would this be useful because I'm doing it manually right now and the exception is logged but I would like to return the error to the user as to what happend and how to fix it?

Why decimal?

I've noticed that django-json-field treats my floating point data as Decimal type. I've seen why you did it by looking at the issues history of the project on GitHub, but I think it's really inconvenient, here's why:

  • Python's default fast JSON encoder (json.dumps) written in C chokes when I give it data I got from a JSONField field (as a part of a larger structure), forcing me to use a custom encoder in Python, which is orders of magnitude slower.
  • Decimal data type itself is hugely slower than float
  • All modern browsers treat the JavaScript "number" type internally as a double precision float, so the added precision of Decimal is lost when transferred to the browser. JSON is not JavaScript, but you must admit it's most commonly used as such.

Could you make an option to be used in the field declaration to treat floats as floats? E.g.
f = JSONField(null=True, pure_float=True)

... or something like it?

TypeError: db_type() got multiple values for keyword argument 'connection'

Hi, I had this error in Django 1.3 with djangotoolbox and AppEngine because inside JSONField.db_type you are not passing the 'connection' param as a keyword argument, here's a fragment of the stack-trace:

File "/.../django/db/models/base.py", line 462, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/.../django/db/models/base.py", line 573, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
File ".../django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
File "/.../django/db/models/query.py", line 1438, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
File "/.../dbindexer/compiler.py", line 38, in execute_sql
    return super(SQLInsertCompiler, self).execute_sql(return_id=return_id)
File ".../db/basecompiler.py", line 368, in execute_sql
    db_type = field.db_type(connection=self.connection)
File "/.../django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
File "/.../json_field/fields.py", line 102, in db_type
    return super(JSONField, self).db_type(connection)
File "/.../django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
File "/.../django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)

for some reason, inside subclassing.py, django 1.3 and djangotoolbox's indexer is messing with the connection param when calling the following function:

def call_with_connection(func):
    arg_names, varargs, varkwargs, defaults = getargspec(func)
    updated = ('connection' in arg_names or varkwargs)
    if not updated:
        warn("A Field class whose %s method hasn't been updated to take a "
            "`connection` argument." % func.__name__,
            DeprecationWarning, stacklevel=3)

    def inner(*args, **kwargs):
        if 'connection' not in kwargs:
            from django.db import connection
            kwargs['connection'] = connection
            warn("%s has been called without providing a connection argument. " %
                func.__name__, DeprecationWarning,
                stacklevel=2)
        if updated:
            return func(*args, **kwargs)
        if 'connection' in kwargs:
            del kwargs['connection']
        return func(*args, **kwargs)
    return inner

I fixed it using this diff but I haven't tested it with other versions

Doesn't support Django 1.3

line 6 of fields.py imports django.utils.timezone, which isn't introduced until Django 1.4, whereas setup.py claims to only require 1.2.7

Wrong default value for South migration

I create a new field on my model as such:

some_json_field = JSONField(default=[], blank=True)

However, when I generate the schemamigration (using python manage.py schemamigration appname --auto) and migrate, the field on existing model instances for the some_json_field are the string "[]" instead of []

TypeError: 'NoneType' object is not iterable - for string that begins with date, but not represent date

Steps to reproduce

>>> import json_field, dateutil
>>> json_field.__version__
'0.5.4'
>>> dateutil.__version__
'2.2'
>>> from json_field.fields import JSONDecoder
>>> from django.utils import simplejson as json
>>>
>>> json_payload = '{"title": "2014-01-27 | Title with date"}'
>>>
>>> json.loads(json_payload)  # default decoder - OK
{u'title': u'2014-01-27 | Title with date'}
>>>
>>> json.loads(json_payload, cls=JSONDecoder)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 351, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/Users/caxap/Work/pd/api/venv/lib/python2.7/site-packages/json_field/fields.py", line 76, in decode
    obj[key] = self.decode(value, recurse=True)
  File "/Users/caxap/Work/pd/api/venv/lib/python2.7/site-packages/json_field/fields.py", line 85, in decode
    return date_parser.parse(obj).date()
  File "/Users/caxap/Work/pd/api/venv/lib/python2.7/site-packages/dateutil/parser.py", line 748, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/Users/caxap/Work/pd/api/venv/lib/python2.7/site-packages/dateutil/parser.py", line 310, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
TypeError: 'NoneType' object is not iterable

Can't install from empty virtualenv

When installing from a empty virtualenv, I get this:

Obtaining django-json-field from git+git://github.com/chronossc/django-json-field.git#egg=django-json-field (from -r requirements.txt (line 12))
Updating /home/crmadm/virtualenvs/crm-prd/src/django-json-field clone
Running setup.py egg_info for package django-json-field
Traceback (most recent call last):
File "", line 14, in
File "/home/crmadm/virtualenvs/crm-prd/src/django-json-field/setup.py", line 1, in
import json_field
File "json_field/init.py", line 1, in
from django.core.exceptions import ImproperlyConfigured
ImportError: No module named django.core.exceptions
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 14, in

File "/home/crmadm/virtualenvs/crm-prd/src/django-json-field/setup.py", line 1, in

import json_field

File "json_field/init.py", line 1, in

from django.core.exceptions import ImproperlyConfigured

ImportError: No module named django.core.exceptions

After installs Django, it works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.