Skip to content

Commit

Permalink
Reverted the doc changes by acdha.
Browse files Browse the repository at this point in the history
Couldn't ever get them built properly and I'm about to overhaul the docs
by hand. Sorry Chris. :(
  • Loading branch information
toastdriven committed Nov 9, 2010
1 parent 99c0f2c commit e061d25
Show file tree
Hide file tree
Showing 21 changed files with 21 additions and 191 deletions.
7 changes: 1 addition & 6 deletions docs/conf.py
Expand Up @@ -22,7 +22,7 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -192,8 +192,3 @@

# If false, no module index is generated.
#latex_use_modindex = True

intersphinx_mapping = {
'py': ('http://docs.python.org/2.6', None),
'django': ('http://docs.djangoproject.com/en/1.2', 'http://docs.djangoproject.com/en/1.2/_objects/'),
}
19 changes: 0 additions & 19 deletions docs/cookbook.rst
Expand Up @@ -4,22 +4,3 @@
Tastypie Cookbook
=================


Adding Custom Values
--------------------

You might encounter cases where you wish to include additional data in a
response which is not obtained from a field or method on your model. You can
easily extend the :meth:`~tastypie.resources.Resource.dehydrate` method to
provide additional values::

class MyModelResource(Resource):
class Meta:
qs = MyModel.objects.all()

def dehydrate(self, bundle):
bundle.data['custom_field'] = "Whatever you want"
return bundle



52 changes: 0 additions & 52 deletions docs/filtering_sorting.rst
Expand Up @@ -4,55 +4,3 @@
Filtering And Sorting
=====================

Basic Filtering
---------------

:class:`~tastypie.resources.ModelResource` provides a basic Django ORM filter
interface. Simply list the resource fields which you'd like to filter on and
the allowed expression in a `filtering` property of your resource's Meta
class::

from tastypie.constants import ALL, ALL_WITH_RELATIONS

class MyResource(ModelResource):
class Meta:
filtering = {
"slug": ('exact', 'startswith',),
"title": ALL,
}

Valid filtering values are: Django ORM filters (e.g. ``startswith``,
``exact``, ``lte``, etc. or the ``ALL`` or ``ALL_WITH_RELATIONS`` constants
defined in :mod:`tastypie.constants`.

These filters will be extracted from URL query strings using the same
double-underscore syntax as the Django ORM::

/api/v1/myresource/?slug=myslug
/api/v1/myresource/?slug__startswith=test

Advanced Filtering
------------------

If you need to filter things other than ORM resources or wish to apply
additional constraints (e.g. text filtering using `django-haystack
<http://haystacksearch.org>` rather than simple database queries) your
:class:`~tastypie.resources.Resource` may define a custom
:meth:`~tastypie.resource.Resource.build_filters` method which allows you to
filter the queryset before processing a request::

from haystack.query import SearchQuerySet

class MyResource(Resource):
def build_filters(self, filters=None):
if filters is None:
filters = {}

orm_filters = super(MyResource, self).build_filters(filters)

if "q" in filters:
sqs = SearchQuerySet().auto_query(filters['q'])

orm_filters = {"pk__in": [ i.pk for i in sqs ]}

return orm_filters
1 change: 0 additions & 1 deletion docs/index.rst
Expand Up @@ -10,4 +10,3 @@ interfaces.

tutorial
settings
reference/index.rst
5 changes: 0 additions & 5 deletions docs/reference/api.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/authentication.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/authorization.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/bundle.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/cache.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/reference/constants.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/exceptions.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/fields.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/http.rst

This file was deleted.

20 changes: 0 additions & 20 deletions docs/reference/index.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/models.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/paginator.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/resources.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/serializers.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/reference/throttle.rst

This file was deleted.

39 changes: 19 additions & 20 deletions docs/tutorial.rst
Expand Up @@ -4,9 +4,9 @@
Getting Started with Tastypie
=============================

Tastypie is a reusable app (that is, it relies only on it's own code and
focuses on providing just a REST-style API) and is suitable for providing an
API to any application without having to modify the sources of that app.
Tastypie is a reusable app (that is, it relies only on it's own code and focuses
on providing just a REST-style API) and is suitable for providing an API to
any application without having to modify the sources of that app.

Not everyone's needs are the same, so Tastypie goes out of it's way to provide
plenty of hooks for overridding or extending how it works.
Expand Down Expand Up @@ -101,9 +101,9 @@ Creating Resources
==================

REST-style architecture talks about resources, so unsurprisingly integrating
with Tastypie involves creating :class:`~tastypie.resources.Resource` classes.
For our simple application, we'll create a file for these in ``myapp/api.py``,
though they can live anywhere in your application::
with Tastypie involves creating ``Resource`` classes. For our simple
application, we'll create a file for these in ``myapp/api.py``, though they can
live anywhere in your application::

# myapp/api.py
from tastypie.resources import ModelResource
Expand All @@ -115,16 +115,16 @@ though they can live anywhere in your application::
queryset = Entry.objects.all()
resource_name = 'entry'

This class, by virtue of being a :class:`~tastypie.resources.ModelResource`
subclass, will introspect all non-relational fields on the ``Entry`` model and
create it's own :mod:`ApiFields <tastypie.fields>` that map to those fields,
much like the way Django's ``ModelForm`` class introspects.
This class, by virtue of being a ``ModelResource`` subclass, will introspect
all non-relational fields on the ``Entry`` model and create it's own
``ApiFields`` that map to those fields, much like the way Django's ``ModelForm``
class introspects.

.. note::

The ``resource_name`` within the ``Meta`` class is optional. If not
provided, it is automatically generated off the classname, removing any
instances of :class:`~tastypie.resources.Resource` and lowercasing the string. So
instances of ``Resource`` and lowercasing the string. So
``EntryResource`` would become just ``entry``.

It's included in this example for clarity, especially when looking at
Expand Down Expand Up @@ -217,9 +217,9 @@ In order to handle our ``user`` relation, we'll need to create a
queryset = Entry.objects.all()
resource_name = 'entry'

We simply created a new :class:`~tastypie.resources.ModelResource` subclass
called ``UserResource``. Then we added a field to ``EntryResource`` that
specified that the ``user`` field points to a ``UserResource`` for that data.
We simply created a new ``ModelResource`` subclass called ``UserResource``.
Then we added a field to ``EntryResource`` that specified that the ``user``
field points to a ``UserResource`` for that data.

Now we should be able to get all of the fields back in our response. But since
we have another full, working resource on our hands, we should hook that up
Expand All @@ -229,9 +229,8 @@ to our API as well. And there's a better way to do it.
Adding To The Api
=================

Tastypie ships with an :class:`~tastypie.api.Api` class, which lets you bind
multiple :class:`Resources <tastypie.resources.Resource>` together to form a
coherent API. Adding it to the mix is simple.
Tastypie ships with an ``Api`` class, which lets you bind multiple ``Resources``
together to form a coherent API. Adding it to the mix is simple.

We'll go back to our URLconf (``urls.py``) and change it to match the
following::
Expand All @@ -251,9 +250,9 @@ following::
(r'^api/', include(v1_api.urls)),
)

Note that we're now creating an :class:`~tastypie.api.Api` instance,
registering our ``EntryResource`` and ``UserResource`` instances with it and
that we've modified the urls to now point to ``v1_api.urls``.
Note that we're now creating an ``Api`` instance, registering our
``EntryResource`` and ``UserResource`` instances with it and that we've
modified the urls to now point to ``v1_api.urls``.

This makes even more data accessible, so if we start up the ``runserver``
again, the following URLs should work:
Expand Down
3 changes: 1 addition & 2 deletions tastypie/constants.py
@@ -1,4 +1,3 @@
#: Enable all basic ORM filters but do not allow filtering across relationships
# For filtering...
ALL = 1
#: Enable all ORM filters, including across relationships
ALL_WITH_RELATIONS = 2

0 comments on commit e061d25

Please sign in to comment.