class EntryResource(ModelResource):
    user = fields.ForeignKey(UserResource, 'user')

class Meta:
    queryset = Entry.objects.all()
    list_allowed_methods = ['get','post']
    detail_allowed_methods = ['post']
    resource_name = 'myapp/entry'

Why there is need to add "POST" in detail_allowed_methods, As I comment detail_allowed_methods "POST" work fine..!

2

There are 2 answers

1
xyres On

It works fine because on commenting out detail_allowed_methods, Tastypie falls back to it's default value, which is:

['get', 'post', 'put', 'delete', 'patch']

So, commenting detail_allowed_methods won't do anything. If you want to disable all methods, set it's value to an empty list:

detail_allowed_methods = []

See Tastypie docs.

0
Railslide On

Posting to list endpoint and posting to detail one has a different meaning. As from Tastypie docs:

To create new resources/objects, you will POST to the list endpoint of a resource. Trying to POST to a detail endpoint has a different meaning in the REST mindset (meaning to add a resource as a child of a resource of the same type).

If you want to allow the same methods for both list and detail you can use allowed_methods which covers both. If you instead want to use different methods between the two, you need to specify allowed methods for each endpoint.

As @xyres said, specifying methods for one endpoint only, will results in the other one falling back on its default (all methods allowed).