Skip to content

Commit 6bae78c

Browse files
fixed #38
1 parent 2158234 commit 6bae78c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Algolyzer/data/quiz_data.json

Whitespace-only changes.

Algolyzer/quiz/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
3+
from django.core.management import call_command
4+
from django.core.management.base import BaseCommand
5+
6+
7+
class Command(BaseCommand):
8+
help = "Dump data for quiz models (Question and Topic) into a JSON file."
9+
10+
def add_arguments(self, parser):
11+
parser.add_argument(
12+
"--output",
13+
type=str,
14+
default="./data/quiz_data.json",
15+
help="Output file path (default: ./data/quiz_data.json)",
16+
)
17+
18+
def handle(self, *args, **kwargs):
19+
output_path = kwargs["output"]
20+
os.makedirs(os.path.dirname(output_path), exist_ok=True)
21+
22+
self.stdout.write("Dumping quiz data into: {}".format(output_path))
23+
24+
call_command(
25+
"dumpdata",
26+
"quiz.Question",
27+
"quiz.Topic",
28+
"--natural-primary",
29+
"--natural-foreign",
30+
"--indent",
31+
"4",
32+
stdout=open(output_path, "w"),
33+
)
34+
35+
self.stdout.write(self.style.SUCCESS("Data dumped successfully!"))

0 commit comments

Comments
 (0)