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

Prototype top and second level APIs #24

Open
mjtamlyn opened this issue Apr 11, 2016 · 2 comments
Open

Prototype top and second level APIs #24

mjtamlyn opened this issue Apr 11, 2016 · 2 comments

Comments

@mjtamlyn
Copy link
Owner

Top level API should be ideally similar to form/serializer, but it should be informed by a "second level" API which is purely functional.

I have something like this in my head:

# Read mode
a = Adapter()
data = a.adapt(initial={'instance': model_instance}) 

# Write mode
a = Adapter()
data = a.adapt(initial={'instance': model_instance}, data=request.data)
processed_data, errors = a.validate(data)
assert not errors
output = a.process(processed_data)
assert output['instance'] == model_instance

Note that no step needs to use a.blah for any blah except the structure of a.

@phalt
Copy link

phalt commented Apr 12, 2016

I'm happy to give this a go :)

@jpic
Copy link
Contributor

jpic commented Mar 6, 2018

Looks great! Just one quick question: how would you create a form with initial data which don't come from a model instance, ie. a plain dict ?

a.adapt(initial={'data': {'email': 'you@example.com'}})

Another question is, how do you add a form field ?

Is it possible to also write this without any model instance to see how this would look like ?

@jpic jpic unassigned phalt Mar 6, 2018
jpic added a commit to jpic/django-adapters that referenced this issue Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants