neo4j-contrib / django-neomodel

Neomodel plugin for Django
MIT License
288 stars 55 forks source link

Extend DjangoNode to be used in Django Restframework ModelSerializers #45

Open contra-bit opened 3 years ago

contra-bit commented 3 years ago

Dear Devs, I am working on building full support for django rest framework. This includes a README over 1000 Lines with full examples on how to build a self documenting rest api specified with OpenAPI 3.0

Problem

Everything works perfect expect for the edge case that the parameters for POST request are separated with hyphen instead of underscores. Everything brakes if properties of a node are in hyphen case (test-name) instead of (test_name)

What i have tried

I have tried a few different approaches.

- Patching [djangorestframework-camel-case ](https://github.com/contra-bit/djangorestframework-camel-case)so it parses underscores from hyphens (result)

Traceback (most recent call last): File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, *kwargs) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/viewsets.py", line 125, in view return self.dispatch(request, args, kwargs) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/mixins.py", line 19, in create self.perform_create(serializer) File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/mixins.py", line 24, in perform_create serializer.save() File "/home/s0/Code/Learn/Neo4JProjects/neo4things/env/lib/python3.9/site-packages/rest_framework/serializers.py", line 205, in save self.instance = self.create(validated_data)


The issue here is that the conversion happens correctly but then i think python is confussed because there is a minus and property name is now an expression

I think the easiest would be to make DjangoNode work in the rest framework. What do you think. Any Ideas how I can get this to work?

If you are interested in my project write me, its going to be published under agpl soon
contra-bit commented 3 years ago

My intuition tells me, that DjangoFields needs the function get_field info or simmilar

whatSocks commented 3 years ago

Hello @contra-bit this is interesting, we will check.