from django.core.management import call_command
from django.core.management.commands import LabelCommand


class Command(LabelCommand):
    def handle_label(self, label, **options):
        # Because django will use the default manager of each model, we
        # monkeypatch the manager to filter by our label before calling
        # the dumpdata command to dump only the subset of data we want.

        # Set the 

        # Call the dumpdata command.
        call_command('dumpdata', 'cbv')

import json

from django.db.models.query import QuerySet
from django.core.management import call_command
from django.core.management.base import LabelCommand
from django.core import serializers
from cbv import models


class Command(LabelCommand):
    """Dump the django cbv app data for a specific version."""
    def handle_label(self, label, **options):
        filtered_models = {
            models.ProjectVersion: 'version_number',
            models.Module: 'project_version__version_number',
            models.ModuleAttribute: 'module__project_version__version_number',
            models.Function: 'module__project_version__version_number',
            models.Klass: 'module__project_version__version_number',
            models.KlassAttribute: 'klass__module__project_version__version_number',
            models.Method: 'klass__module__project_version__version_number',
        }
        objects = []
        for model, version_arg in filtered_models.items():
            filter_kwargs = {version_arg: label}
            result = model.objects.filter(**filter_kwargs)
            objects = objects + list(result)
        for obj in objects:
            obj.pk = None
        dump = serializers.serialize('json', objects, indent=1, use_natural_keys=True)
        self.stdout.write(dump)

Allow dumpdata of specific version of cbv.