def find(self, obj, filter_to_class=Ingredient, constructor=None):
        """
        Find an Ingredient, optionally using the shelf.

        :param obj: A string or Ingredient
        :param filter_to_class: The Ingredient subclass that obj must be an
         instance of
        :param constructor: An optional callable for building Ingredients
         from obj
        :return: An Ingredient of subclass `filter_to_class`
        """
        if callable(constructor):
            obj = constructor(obj, shelf=self)

        if isinstance(obj, basestring):
            set_descending = obj.startswith('-')
            if set_descending:
                obj = obj[1:]

            if obj not in self:
                raise BadRecipe("{} doesn't exist on the shelf".format(obj))

            ingredient = self[obj]
            if not isinstance(ingredient, filter_to_class):
                raise BadRecipe('{} is not a {}'.format(obj, filter_to_class))

            if set_descending:
                ingredient.ordering = 'desc'

            return ingredient
        elif isinstance(obj, filter_to_class):
            return obj
        else:
            raise BadRecipe('{} is not a {}'.format(obj, filter_to_class))
def find ( self , obj , filter_to_class = Ingredient , constructor = None ) : if callable ( constructor ) : obj = constructor ( obj , shelf = self ) if isinstance ( obj , basestring ) : set_descending = obj . startswith ( '-' ) if set_descending : obj = obj [ 1 : ] if obj not in self : raise BadRecipe ( "{} doesn't exist on the shelf" . format ( obj ) ) ingredient = self [ obj ] if not isinstance ( ingredient , filter_to_class ) : raise BadRecipe ( '{} is not a {}' . format ( obj , filter_to_class ) ) if set_descending : ingredient . ordering = 'desc' return ingredient elif isinstance ( obj , filter_to_class ) : return obj else : raise BadRecipe ( '{} is not a {}' . format ( obj , filter_to_class ) )
Find an Ingredient, optionally using the shelf.

        :param obj: A string or Ingredient
        :param filter_to_class: The Ingredient subclass that obj must be an
         instance of
        :param constructor: An optional callable for building Ingredients
         from obj
        :return: An Ingredient of subclass `filter_to_class`