[Django]-Creating a tastypie resource with a foreign key without exposing the foreign key as a resource

3👍

If you don’t want a foreign key to be visible on api, just don’t make a field for it in the resource.
If you need to specify some value to it on create/update you can overwrite obj_create/obj_update tastypie methods for this resource. For example:

def obj_create(self, bundle, request=None, **kwargs):
    obj = super(YourResource, self).obj_create(bundle, request, **kwargs)
    obj.yourforeighnkey = somevalue
    obj.save()
    return obj   

Leave a comment