Re: NoneType object has no attribute in POST/PUT a resource with nested resources (django, tastypie)

2012-05-14 Thread Alberto Díaz
Thanks and sorry Karen

El jueves, 10 de mayo de 2012 14:04:10 UTC+2, Karen Tracey escribió:
>
> Please ask questions about using Django on django-users, not here. The 
> topic of this list is the development of Django itself. (Also when you post 
> to django-users for this problem it would help people help you if you 
> included the full traceback you are getting.)
>
> Karen
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/UqcF5pI2mSwJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.



Re: NoneType object has no attribute in POST/PUT a resource with nested resources (django, tastypie)

2012-05-10 Thread Karen Tracey
Please ask questions about using Django on django-users, not here. The
topic of this list is the development of Django itself. (Also when you post
to django-users for this problem it would help people help you if you
included the full traceback you are getting.)

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.



NoneType object has no attribute in POST/PUT a resource with nested resources (django, tastypie)

2012-05-10 Thread Alberto Díaz
Hi all,

I've been digging in this problem and haven't found how to solve it. I've 
got two secure resources, ComplementoResource and ProductoResource defined 
as follow:

class ComplementoResource(CommonModelResource):
  restaurante = fields.ForeignKey(RestauranteResource, 'restaurante')
  restaurante_id = fields.IntegerField(attribute='restaurante_id')

  class Meta:
queryset = Complemento.objects.all()
resource_name = 'complementos'
list_allowed_methods = ['get', 'post', 'put', 'delete']
authentication = tastypie.authentication.ApiKeyAuthentication()
authorization = tastypie.authorization.Authorization()

  def alter_list_data_to_serialize(self, request, data):
return self.alter_json_list(data, 'complementos')

  def apply_authorization_limits(self, request, object_list):
return object_list.filter(restaurante__user=request.user)


class ProductoResource(CommonModelResource):
  restaurante = fields.ForeignKey(RestauranteResource, 'restaurante')
  restaurante_id = fields.IntegerField(attribute='restaurante_id')
  complementos = fields.ManyToManyField(ComplementoResource, 
'complementos', full=True)

  class Meta:
queryset = Producto.objects.all()
resource_name = 'productos'
list_allowed_methods = ['get', 'post', 'put', 'delete']
authentication = tastypie.authentication.ApiKeyAuthentication()
authorization = tastypie.authorization.Authorization()

  def alter_list_data_to_serialize(self, request, data):
return self.alter_json_list(data, 'productos')

  def apply_authorization_limits(self, request, object_list):
return object_list.filter(restaurante__user=request.user)

The problem comes when I try to post a new entity Producto with one or more 
entities from Complemento. I get "'NoneType' object has no attribute 
'user'" error message. The request parameter in the 
method apply_authorization_limits of CombinadoResource get's a value of 
None. After digging a bit, I've seen that in the  file fields.py, there is 
a method called resource_from_data used, and in line 548 (at least in my 
version) that says:

return fk_resource.obj_update(fk_bundle, **data)

This method has the correct request value, but doesn't pass it 
to fk_resource.obj_updat, so it get's the default value (None) and after 
two or three mor calls the error raises. And the funny thing is that I get 
an error but the new entity Producto is inserted (without entities of 
Complementos).

Anybody knows if I'm going in the wrong way and this things have to be done 
otherwise? And the other question, anybody knows how to abort the insertion 
of the entity Producto if entities of Complement are not inserted?

Thank you all very much

Alberto

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/nj9wpfS-urEJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.