I'm using tastypie and I want to create a Resource
for a "singleton" non-model object.
For the purposes of this question, let's assume what I want the URL to represent is some system settings that exist in an ini
file.
What this means is that...:
- The fields I return for this URL will be custom created for this
Resource
- there is no model that contains this information. - I want a single URL that will return the data, e.g. a
GET
request on/api/v1/settings
. - The returned data should return in a format that is similar to a details URL - i.e., it should not have
meta
andobjects
parts. It should just contain the fields from the settings. - It should not be possible to
GET
a list of such object nor is it possible to performPOST
,DELETE
orPUT
(this part I know how to do, but I'm adding this here for completeness). - Optional: it should play well with
tastypie-swagger
for API exploration purposes.
I got this to work, but I think my method is kind of ass-backwards, so I want to know what is the common wisdom here. What I tried so far is to override dehydrate
and do all the work there. This requires me to override obj_get
but leave it empty (which is kind of ugly) and also to remove the need for id
in the details url by overriding override_urls
.
Is there a better way of doing this?