Преглед изворни кода

adding fixtures stub and load_initial_data management command

David Ray пре 8 година
родитељ
комит
3e5ce066f8

+ 18 - 0
bakerydemo/base/fixtures/bakerydemo.json

@@ -0,0 +1,18 @@
+[{
+    "model": "auth.user",
+    "pk": 1,
+    "fields": {
+        "password": "pbkdf2_sha256$30000$E9Uhcl4mkQtv$WxS3m0ZzdJXWmI7nAae9wmybd2L2HK5zgjHHXc65+oo=",
+        "last_login": null,
+        "is_superuser": true,
+        "username": "admin",
+        "first_name": "",
+        "last_name": "",
+        "email": "",
+        "is_staff": true,
+        "is_active": true,
+        "date_joined": "2017-02-10T12:48:21.920Z",
+        "groups": [],
+        "user_permissions": []
+    }
+}]

+ 0 - 0
bakerydemo/base/management/__init__.py


+ 0 - 0
bakerydemo/base/management/commands/__init__.py


+ 13 - 0
bakerydemo/base/management/commands/load_initial_data.py

@@ -0,0 +1,13 @@
+import os
+
+from django.conf import settings
+from django.core.management.base import BaseCommand
+from django.core.management import call_command
+
+
+class Command(BaseCommand):
+    def handle(self, **options):
+        fixtures_dir = os.path.join(settings.BASE_DIR, 'base', 'fixtures')
+        fixture_file = os.path.join(fixtures_dir, 'bakerydemo.json')
+
+        call_command('loaddata', fixture_file, verbosity=0)