class WorkloadResource(ModelResource): # blueprints = ManyToManyField(Blueprint, 'blueprints') blueprint = fields.OneToManyField('catalog.api.BlueprintResource', attribute='blueprint', related_name='workloads', full=True, null=True) def obj_create(self, bundle, request=None, **kwargs): # return super(WorkloadResource, self).obj_create(bundle, request, **kwargs) return super(WorkloadResource, self).obj_create(bundle, request=request, **kwargs) def obj_update(self, bundle, request=None, **kwargs): workload = Workload.objects.get(id=kwargs.get("pk")) workload.description = bundle.data.get("description") workload.name = bundle.data.get("name") workload.image = bundle.data.get("image") workload.flavor = bundle.data.get("flavor") workload.save() def obj_delete(self, bundle, **kwargs): return super(WorkloadResource, self).obj_delete(bundle) def determine_format(self, request): return 'application/json' class Meta: queryset = Workload.objects.all() resource_name = 'workload' authorization=Authorization() filtering = { "blueprint": ('exact', ), }
When I use curl to POST:curl -i -H "Content-Type: application/json" -X POST -d
where wkl.json is:
@wkl.json http://localhost:8000/api/workload/{ "name":"w 5", "description":"w 5 desc" }
I get this error:AttributeError: 'Workload' object has no attribute 'blueprint'
I do need to have this attribute, so I can list all child workloads for a given blueprint
like this:GET /api/workload/?blueprint=1
but I need to exclude this 'blueprint' attribute from participating in the obj_create
What is the proper place and syntax to do this?
-Eugene