Mamy pęknięty kod!
class ContentTypeResource(ModelResource):
class Meta:
queryset = ContentType.objects.all()
resource_name = 'content_type'
allowed_methods = ['get',]
class PageObjectResource(ModelResource):
content_object = fields.CharField()
content_type = fields.ToOneField(
ContentTypeResource,
attribute = 'content_type',
full=True)
class Meta:
queryset = models.PageObject.objects.all()
resource_name = 'page_object'
allowed_methods = ['get',]
def dehydrate_content_object(self, bundle):
for resource in api._registry.values():
if resource._meta.object_class == bundle.obj.content_object.__class__:
return resource.full_dehydrate(resource.build_bundle(obj=bundle.obj.content_object, request=bundle.request)).data
return ''
co skutkuje czymś takim:
"page_objects": [
{
"content_object": {
"id": "186",
"look_stills": [
{
"_image": "/static/media/uploads/looks/DSC_0903_PR_MEDIUM_QUALITY_RGB_FA.jpg",
"aspect": "front",
"id": "186",
"look_still_icons": [
{
"colour_code": "58",
"enabled": true,
"id": "186",
"in_stock_only": true,
"look_product": {
"colour_code": "58",
"enabled": true,
"id": "186",
"resource_uri": "/api/look_product/186/",
"style_code": "420215"
},
"resource_uri": "/api/look_still_icon/186/",
"x_coord": 76,
"y_coord": 5
}
],
"ordering": 1,
"resource_uri": "/api/look_still/186/"
}
],
"resource_uri": "/api/look_still_set/186/",
"slug": ""
},
"content_type": {
"app_label": "looks_beta",
"id": "97",
"model": "lookstillset",
"name": "look still set",
"resource_uri": "/api/content_type/97/"
},
"id": "2",
"object_id": 186,
"resource_uri": "/api/page_object/2/"
}
],
"page_order": 3,
"page_template": "look_still",
"resource_uri": "/api/page/2/",
"slug": "",
"spread_number": 2,
"title": ""
},
Czy kiedykolwiek działałaś tak, nie stosując łatek do smaku? –