Ticket #33974: test_serializer.py
File test_serializer.py, 495 bytes (added by , 2 years ago) |
---|
Line | |
---|---|
1 | from django.core.management.base import BaseCommand, CommandError |
2 | from serializertest.models import Board |
3 | from django.core.serializers import serialize |
4 | import json |
5 | |
6 | class Command(BaseCommand): |
7 | help = '' |
8 | |
9 | def handle(self, *args, **options): |
10 | obj = Board.objects.first() |
11 | if not obj: |
12 | pieces = [1, 3, 5] |
13 | obj = Board() |
14 | obj.pieces = pieces |
15 | obj.save() |
16 | |
17 | print(serialize('json', [obj])) |
18 | print(json.dumps(obj.pieces)) |