g-cassie / ember-drf Goto Github PK
View Code? Open in Web Editor NEWDjango Rest Framework adapters for Ember Data
Django Rest Framework adapters for Ember Data
An error occurs when trying to use ember_drf.renderers.ActiveModelJSONRenderer
with Django-Rest-Framework 3.0 beta. It seems like ManyRelation
, imported in ember_drf.utils
, is not included in the 3.0 beta, but is present on the 3.0 branch.
ImportError: Could not import 'ember_drf.renderers.ActiveModelJSONRenderer' for API setting 'DEFAULT_RENDERER_CLASSES'. ImportError: cannot import name ManyRelation.
Is there anything I can do ?
Hi, I have a model which has some nested relations, something like:
class Document(models.Model):
node_positions = models.ManyToMany('NodePosition')
def get_nodes(self):
return Node.objects.filter(node_position__document=self)
class NodePosition(models.Model):
node = models.ForeignKey('Node')
class Node(models.Model):
pass
and I would like, when fetching a document, to sideload both NodePositions and Nodes. However, due to the way the SideloadSerializer is implemented, it depends on django-reported relations, which don't include Nodes. So if my DocumentBaseSerializer does
class DocumentBaseSerializer(serializers.ModelSerializer):
nodes = serializers.ReadOnlyField(source='get_nodes')
I get the node IDs but I am not able to sideload the nodes. I am thinking of overriding _configure_sideloads to try and support this use case as well, but I'm wondering if you have tried this before or have any input on the matter. Thanks!
Hi,
I'd like to sideload data with multi-level relationships such as :
{
"workoutPlan": {
"id": 1999,
"name": "Test Plan",
"workout_ids": [ 12452, 12453 ],
},
"workouts": [
{
"id": 12452,
"exercise_ids": [ 114322 ]
}, {
"id": 12453,
"exercise_ids": [ 114323 ]
}
],
"exercises": [
{ "id": 114322 },
{ "id": 114323 }
]
}
I tried to call the SideloadSerializer into sideloads:
class WorkoutPlanSideloadSerializer(SideloadSerializer):
class Meta:
base_serializer = WorkoutPlanSerializer
sideloads = [
(Workout, WorkoutSideloadSerializer)
]
class WorkoutSideloadSerializer(SideloadSerializer):
class Meta:
base_serializer = WorkoutSerializer
sideloads = [
(Exercise, ExerciseSerializer)
]
But I get something like:
{
"workoutPlan": {
"id": 1999,
"name": "Test Plan",
"workout_ids": [ 12452, 12453 ],
},
"workouts": {
"workouts": [
{
"id": 12452,
"exercise_ids": [ 114322 ]
}, {
"id": 12453,
"exercise_ids": [ 114323 ]
}
],
"exercises": [
{ "id": 114322 },
{ "id": 114323 }
]
},
}
Is there a way to get the correct json output ?
Thank you !
If I have the following models:
class BigThing(models.Model):
name = models.CharField(max_length=100)
favorite = models.OneToOneField('ChildThing', related_name='favorite_of')
class ChildThing(models.Model):
father = models.ForeignKey(BigThing)
name = models.CharField(max_length=100)
A ValueError is raised even if I'm not including the field favorite_of
in the ChildThingSerializer.
Made a commit to the same repo to show the problem. https://github.com/wichovw/emberdrf-sideload-example
Thnx!!!
As discussed in #1 the ActiveModelJSONRenderer is currently broken due to ReturnDict
instances no longer being nested.
I have a PR into DRF here encode/django-rest-framework#2119 and at this stage am optimistic that we can get the needed changes made in the short term. If that discussion appears to stagnate I will look for a work around (though it will either involve modifying DRF or moving behaviour into the serializer).
The error: 'QuerySet' object has no attribute 'pk'
field.get_attribute
seems to return a QuerySet
instead of a list
, which obviously breaks the test if isinstance(attribute, list):
.
I'm trying to get the basic example of sideloading work, but getting a TypeError.
I'm using:
Django==1.8.2
djangorestframework==3.1.3
emberdrf==0.1.8
inflection==0.3.1
Here is a very simple django project with the problem replicated: https://github.com/wichovw/emberdrf-sideload-example
Everything works fine until I try to add sideload to the SideloadSerializer (lines 19-21 of /example/serializers.py)
Any help will be useful. Thnx!!
Django Rest Framework v 3.2 has removed the deprecated request.QUERY_PARAMS
, and ember-drf is now throwing a NotImplementedError at https://github.com/g-cassie/ember-drf/blob/master/ember_drf/filters.py#L12
If a fix isn't already in the works on your end I'd be happy to create a pull request, just let me know.
Thanks for the great package!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.