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

Support for Django 1.8 ArrayField #2496

Merged
merged 6 commits into from
Feb 5, 2015
Merged

Support for Django 1.8 ArrayField #2496

merged 6 commits into from
Feb 5, 2015

Conversation

jpadilla
Copy link
Member

@jpadilla jpadilla commented Feb 1, 2015

Add models.ArrayField in Django 1.8 to serializers.ListField mapping by default when using a ModelSerializer.

>>> print(ChessBoardSerializer())
ChessBoardSerializer():
    board = ListField(validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>])

@jpadilla jpadilla added this to the 3.1.0 Release milestone Feb 1, 2015
@tomchristie
Copy link
Member

Nice. We'll also want to figure out how to populate the child argument.

@jpadilla
Copy link
Member Author

jpadilla commented Feb 1, 2015

@tomchristie doh yeah, completely missed that. Working on it.

@jpadilla
Copy link
Member Author

jpadilla commented Feb 5, 2015

@tomchristie not sure if that's the best solution. Thoughts?

>>> ChessBoardSerializer()
ChessBoardSerializer():
    board = ListField(child=CharField(allow_blank=True, allow_null=True, label='Board', max_length=10, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>])

@tomchristie
Copy link
Member

Very nice! 🚀

I tried adding a test and bumped into the fairly major issue that we'd need to start using postgres as our test database (no, I don't want us to have to do that).

Only thing I'd like to see before we commit this is a double check that it really does work for nested array fields. The example you gave above doesn't quite match up to the example in the Django docs, as the representation is only listing ListField(child=CharField()), not ListField(child=ListField(child=CharField()))` - once that's double checked I'm happy for this to go in.

@jpadilla
Copy link
Member Author

jpadilla commented Feb 5, 2015

@tomchristie yeah I'm looking into that. I did model_field.base_field.base_field which was obviously wrong. That should be kind of an easy fix. Also, should we doing anything with ArrayField.size?

@jpadilla
Copy link
Member Author

jpadilla commented Feb 5, 2015

@tomchristie yeah I think that was an easy fix.

>>> ChessBoardSerializer()
ChessBoardSerializer():
    board = ListField(
        child=ListField(
            child=CharField(allow_blank=True, allow_null=True, label='Board', max_length=10, required=False),
            label='Board',
            validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]
        ),
        validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]
    )

Does that look good?

@tomchristie
Copy link
Member

Stellar! 🌟

tomchristie added a commit that referenced this pull request Feb 5, 2015
Support for Django 1.8 ArrayField
@tomchristie tomchristie merged commit f1e7ce5 into encode:version-3.1 Feb 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants