Ticket #5610: dumpdata-improvements.diff

File dumpdata-improvements.diff, 1.7 KB (added by David Reynolds, 17 years ago)

Small improvement to dumpdata

  • django/core/management/commands/dumpdata.py

    diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
    index 7bdcc42..1238e93 100644
    a b class Command(BaseCommand):  
    1313    args = '[appname ...]'
    1414
    1515    def handle(self, *app_labels, **options):
    16         from django.db.models import get_app, get_apps, get_models
     16        from django.db.models import get_app, get_apps, get_models, get_model
    1717        from django.core import serializers
    1818
    1919        format = options.get('format', 'json')
    2020        indent = options.get('indent', None)
    21 
     21       
    2222        if len(app_labels) == 0:
    2323            app_list = get_apps()
    2424        else:
    25             app_list = [get_app(app_label) for app_label in app_labels]
     25            app_list = []
     26            model_list = []
     27            for app_label in app_labels:
     28                app_model_label = app_label.split('.')
     29                if len(app_model_label) <= 1:
     30                    app_list.append(get_app(app_label))
     31                else:
     32                    model_list.append(get_model(app_model_label[0], app_model_label[1]))
    2633
    2734        # Check that the serialization format exists; this is a shortcut to
    2835        # avoid collating all the objects and _then_ failing.
    class Command(BaseCommand):  
    3542        for app in app_list:
    3643            for model in get_models(app):
    3744                objects.extend(model.objects.all())
     45               
     46        for model in model_list:
     47            objects.extend(model.objects.all())
     48
    3849        try:
    3950            return serializers.serialize(format, objects, indent=indent)
    4051        except Exception, e:
Back to Top