<commit_before>========
Examples
========

Sometimes, an example is much easier to understand than abstract API docs, so here's some sample use cases.

Case 1: Simple Blog API
=======================

models.py
---------

.. code-block:: python

    from django.db import models
    from taggit.managers import TaggableManager

    class Post(models.Model):
        title = models.CharField(max_length=255)
        author = models.ForeignKey('auth.User')
        published = models.BooleanField(default=False)
        content = models.TextField(blank=True)
        tags = TaggableManager(blank=True)


serialiser.py
-------------

.. code-block:: python

    from nap.models import ModelSerialiser
    from nap import fields

    class PostSerialiser(ModelSerialiser):
        class Meta:
            model = models.Post

        tags = fields.Field()

        def deflate_tags(self, obj, \**kwargs):
            '''Turn the tags into a flat list of names'''
            return [tag.name for tag in obj.tags.all()]


publishers.py
-------------

.. code-block:: python
    
    from nap.models import ModelPublisher
    from .serialiser import PostSerialiser

    class PostPublisher(ModelPublisher):
        serialiser = PostSerialiser()

urls.py<commit_msg>Remove trailing whitespace<commit_after>========
Examples
========

Sometimes, an example is much easier to understand than abstract API docs, so here's some sample use cases.

Case 1: Simple Blog API
=======================

models.py
---------

.. code-block:: python

    from django.db import models
    from taggit.managers import TaggableManager

    class Post(models.Model):
        title = models.CharField(max_length=255)
        author = models.ForeignKey('auth.User')
        published = models.BooleanField(default=False)
        content = models.TextField(blank=True)
        tags = TaggableManager(blank=True)


serialiser.py
-------------

.. code-block:: python

    from nap.models import ModelSerialiser
    from nap import fields

    class PostSerialiser(ModelSerialiser):
        class Meta:
            model = models.Post

        tags = fields.Field()

        def deflate_tags(self, obj, \**kwargs):
            '''Turn the tags into a flat list of names'''
            return [tag.name for tag in obj.tags.all()]


publishers.py
-------------

.. code-block:: python

    from nap.models import ModelPublisher
    from .serialiser import PostSerialiser

    class PostPublisher(ModelPublisher):
        serialiser = PostSerialiser()

urls.py
{'fraction_non_alphanumeric': 0.1369212504946577, 'fraction_numerical': 0.0031658092599920855, 'mean_word_length': 2.6165951359084407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1153808', 'n_tokens_mistral': 703, 'n_tokens_neox': 655, 'n_words': 205}