Browse Source

README.md

ChangkeYang 7 years ago
parent
commit
39b4709d37

+ 149 - 91
.idea/workspace.xml

@@ -2,8 +2,14 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="33a8caf6-56b3-4b8d-a4ba-9f9f2e8d8e9c" name="Default" comment="">
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/vcs.xml" />
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/api/task/urls.py" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/db.sqlite3" afterPath="$PROJECT_DIR$/db.sqlite3" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/api/task/admin.py" afterPath="$PROJECT_DIR$/api/task/admin.py" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/api/task/models.py" afterPath="$PROJECT_DIR$/api/task/models.py" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/api/task/views.py" afterPath="$PROJECT_DIR$/api/task/views.py" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/todo/settings.py" afterPath="$PROJECT_DIR$/todo/settings.py" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/todo/urls.py" afterPath="$PROJECT_DIR$/todo/urls.py" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="TRACKING_ENABLED" value="true" />
@@ -18,18 +24,18 @@
   <component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
   <component name="FileEditorManager">
     <leaf>
-      <file leaf-file-name="settings.py" pinned="false" current-in-tab="false">
+      <file leaf-file-name="settings.py" pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/todo/settings.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="189">
-              <caret line="39" column="4" lean-forward="false" selection-start-line="39" selection-start-column="4" selection-end-line="39" selection-end-column="4" />
+            <state relative-caret-position="386">
+              <caret line="57" column="8" lean-forward="false" selection-start-line="55" selection-start-column="3" selection-end-line="57" selection-end-column="8" />
               <folding />
             </state>
           </provider>
         </entry>
       </file>
       <file leaf-file-name="__init__.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/task/__init__.py">
+        <entry file="file://$PROJECT_DIR$/api/__init__.py">
           <provider selected="true" editor-type-id="text-editor">
             <state relative-caret-position="0">
               <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
@@ -38,89 +44,120 @@
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="__init__.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/__init__.py">
+      <file leaf-file-name="models.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/models.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="0">
-              <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
-              <folding />
+            <state relative-caret-position="105">
+              <caret line="7" column="10" lean-forward="false" selection-start-line="7" selection-start-column="6" selection-end-line="7" selection-end-column="10" />
+              <folding>
+                <element signature="e#16#55#0" expanded="true" />
+              </folding>
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="admin.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/task/admin.py">
+      <file leaf-file-name="serializers.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/serializers.py">
           <provider selected="true" editor-type-id="text-editor">
             <state relative-caret-position="45">
-              <caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
+              <caret line="3" column="6" lean-forward="false" selection-start-line="3" selection-start-column="6" selection-end-line="3" selection-end-column="6" />
+              <folding>
+                <element signature="e#0#29#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file leaf-file-name="0002_auto_20170604_0220.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/migrations/0002_auto_20170604_0220.py">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="300">
+              <caret line="22" column="47" lean-forward="false" selection-start-line="22" selection-start-column="47" selection-end-line="22" selection-end-column="47" />
               <folding />
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="apps.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/task/apps.py">
+      <file leaf-file-name="0001_initial.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/migrations/0001_initial.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="90">
-              <caret line="6" column="12" lean-forward="true" selection-start-line="6" selection-start-column="12" selection-end-line="6" selection-end-column="12" />
-              <folding>
-                <element signature="e#0#39#0" expanded="true" />
-              </folding>
+            <state relative-caret-position="330">
+              <caret line="24" column="25" lean-forward="false" selection-start-line="24" selection-start-column="17" selection-end-line="24" selection-end-column="25" />
+              <folding />
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="models.py" pinned="false" current-in-tab="true">
-        <entry file="file://$PROJECT_DIR$/api/task/models.py">
+      <file leaf-file-name="views.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/views.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="120">
-              <caret line="8" column="14" lean-forward="false" selection-start-line="8" selection-start-column="14" selection-end-line="8" selection-end-column="14" />
+            <state relative-caret-position="210">
+              <caret line="14" column="0" lean-forward="false" selection-start-line="14" selection-start-column="0" selection-end-line="14" selection-end-column="0" />
               <folding>
-                <element signature="e#0#39#0" expanded="true" />
+                <element signature="e#0#35#0" expanded="true" />
               </folding>
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="0001_initial.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/task/migrations/0001_initial.py">
+      <file leaf-file-name="admin.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/admin.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="330">
-              <caret line="24" column="25" lean-forward="false" selection-start-line="24" selection-start-column="17" selection-end-line="24" selection-end-column="25" />
-              <folding />
+            <state relative-caret-position="75">
+              <caret line="5" column="22" lean-forward="false" selection-start-line="5" selection-start-column="22" selection-end-line="5" selection-end-column="22" />
+              <folding>
+                <element signature="e#0#32#0" expanded="true" />
+              </folding>
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="tests.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/task/tests.py">
+      <file leaf-file-name="urls.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/api/task/urls.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="45">
-              <caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
-              <folding />
+            <state relative-caret-position="90">
+              <caret line="6" column="49" lean-forward="false" selection-start-line="6" selection-start-column="45" selection-end-line="6" selection-end-column="49" />
+              <folding>
+                <element signature="e#0#32#0" expanded="true" />
+              </folding>
             </state>
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="views.py" pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/api/task/views.py">
+      <file leaf-file-name="urls.py" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/todo/urls.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="45">
-              <caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
-              <folding />
+            <state relative-caret-position="330">
+              <caret line="22" column="0" lean-forward="false" selection-start-line="22" selection-start-column="0" selection-end-line="22" selection-end-column="0" />
+              <folding>
+                <element signature="e#638#679#0" expanded="true" />
+              </folding>
             </state>
           </provider>
         </entry>
       </file>
     </leaf>
   </component>
+  <component name="FileTemplateManagerImpl">
+    <option name="RECENT_TEMPLATES">
+      <list>
+        <option value="Python Script" />
+      </list>
+    </option>
+  </component>
   <component name="Git.Settings">
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
   </component>
   <component name="IdeDocumentHistory">
     <option name="CHANGED_PATHS">
       <list>
+        <option value="$PROJECT_DIR$/api/task/migrations/0002_auto_20170604_0220.py" />
+        <option value="$PROJECT_DIR$/todo/urls.py" />
+        <option value="$PROJECT_DIR$/api/task/urls.py" />
+        <option value="$PROJECT_DIR$/api/task/admin.py" />
         <option value="$PROJECT_DIR$/api/task/models.py" />
+        <option value="$PROJECT_DIR$/api/task/serializers.py" />
+        <option value="$PROJECT_DIR$/api/task/views.py" />
         <option value="$PROJECT_DIR$/todo/settings.py" />
       </list>
     </option>
@@ -132,6 +169,7 @@
     <sorting>DEFINITION_ORDER</sorting>
   </component>
   <component name="ProjectFrameBounds">
+    <option name="x" value="1" />
     <option name="y" value="23" />
     <option name="width" value="1024" />
     <option name="height" value="741" />
@@ -212,28 +250,6 @@
               <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
             </PATH_ELEMENT>
           </PATH>
-          <PATH>
-            <PATH_ELEMENT>
-              <option name="myItemId" value="todo" />
-              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
-            </PATH_ELEMENT>
-            <PATH_ELEMENT>
-              <option name="myItemId" value="todo" />
-              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-            </PATH_ELEMENT>
-            <PATH_ELEMENT>
-              <option name="myItemId" value="api" />
-              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-            </PATH_ELEMENT>
-            <PATH_ELEMENT>
-              <option name="myItemId" value="task" />
-              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-            </PATH_ELEMENT>
-            <PATH_ELEMENT>
-              <option name="myItemId" value="migrations" />
-              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-            </PATH_ELEMENT>
-          </PATH>
         </subPane>
       </pane>
     </panes>
@@ -467,10 +483,10 @@
     <servers />
   </component>
   <component name="ToolWindowManager">
-    <frame x="0" y="23" width="1024" height="741" extended-state="6" />
+    <frame x="1" y="23" width="1024" height="741" extended-state="6" />
     <editor active="true" />
     <layout>
-      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.29785156" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
+      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25097656" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
       <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
       <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
@@ -502,20 +518,12 @@
     <watches-manager />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/api/task/admin.py">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="45">
-          <caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/api/task/apps.py">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="90">
           <caret line="6" column="12" lean-forward="true" selection-start-line="6" selection-start-column="12" selection-end-line="6" selection-end-column="12" />
           <folding>
-            <element signature="e#0#39#0" expanded="true" />
+            <element signature="e#0#39#0" expanded="false" />
           </folding>
         </state>
       </provider>
@@ -528,55 +536,105 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/api/task/views.py">
+    <entry file="file://$PROJECT_DIR$/api/task/__init__.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="45">
-          <caret line="3" column="0" lean-forward="true" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
+        <state relative-caret-position="0">
+          <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/todo/settings.py">
+    <entry file="file://$PROJECT_DIR$/api/__init__.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="189">
-          <caret line="39" column="4" lean-forward="false" selection-start-line="39" selection-start-column="4" selection-end-line="39" selection-end-column="4" />
+        <state relative-caret-position="0">
+          <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/api/task/__init__.py">
+    <entry file="file://$PROJECT_DIR$/api/task/migrations/0001_initial.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="0">
-          <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
+        <state relative-caret-position="330">
+          <caret line="24" column="25" lean-forward="false" selection-start-line="24" selection-start-column="17" selection-end-line="24" selection-end-column="25" />
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/api/__init__.py">
+    <entry file="file://$PROJECT_DIR$/api/task/migrations/0002_auto_20170604_0220.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="0">
-          <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
+        <state relative-caret-position="300">
+          <caret line="22" column="47" lean-forward="false" selection-start-line="22" selection-start-column="47" selection-end-line="22" selection-end-column="47" />
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/api/task/migrations/0001_initial.py">
+    <entry file="file://$PROJECT_DIR$/todo/urls.py">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="330">
-          <caret line="24" column="25" lean-forward="false" selection-start-line="24" selection-start-column="17" selection-end-line="24" selection-end-column="25" />
-          <folding />
+          <caret line="22" column="0" lean-forward="false" selection-start-line="22" selection-start-column="0" selection-end-line="22" selection-end-column="0" />
+          <folding>
+            <element signature="e#638#679#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/api/task/admin.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="75">
+          <caret line="5" column="22" lean-forward="false" selection-start-line="5" selection-start-column="22" selection-end-line="5" selection-end-column="22" />
+          <folding>
+            <element signature="e#0#32#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/api/task/serializers.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="45">
+          <caret line="3" column="6" lean-forward="false" selection-start-line="3" selection-start-column="6" selection-end-line="3" selection-end-column="6" />
+          <folding>
+            <element signature="e#0#29#0" expanded="true" />
+          </folding>
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/api/task/models.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="120">
-          <caret line="8" column="14" lean-forward="false" selection-start-line="8" selection-start-column="14" selection-end-line="8" selection-end-column="14" />
+        <state relative-caret-position="105">
+          <caret line="7" column="10" lean-forward="false" selection-start-line="7" selection-start-column="6" selection-end-line="7" selection-end-column="10" />
           <folding>
-            <element signature="e#0#39#0" expanded="true" />
+            <element signature="e#16#55#0" expanded="true" />
           </folding>
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/api/task/urls.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="90">
+          <caret line="6" column="49" lean-forward="false" selection-start-line="6" selection-start-column="45" selection-end-line="6" selection-end-column="49" />
+          <folding>
+            <element signature="e#0#32#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/api/task/views.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="210">
+          <caret line="14" column="0" lean-forward="false" selection-start-line="14" selection-start-column="0" selection-end-line="14" selection-end-column="0" />
+          <folding>
+            <element signature="e#0#35#0" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/todo/settings.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="386">
+          <caret line="57" column="8" lean-forward="false" selection-start-line="55" selection-start-column="3" selection-end-line="57" selection-end-column="8" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
   </component>
 </project>

+ 170 - 0
README.md

@@ -0,0 +1,170 @@
+## Django toturial
+* [Document](https://docs.djangoproject.com/en/1.11/)
+* [Official toturial](https://docs.djangoproject.com/en/1.11/intro/tutorial01/)
+
+### Create a virtual environment
+    mkvirtualenv todo
+    or
+    python –m venv todo
+
+### Activate the environment (Linux and OS X)
+    source todo/bin/activate
+
+### Activate the environment (Windows)
+    todo\Scripts\activate
+
+### Install Django to the active environment
+    pip install django
+
+### Create a new project
+    django-admin.py startproject todo
+
+### Create a database
+    python manage.py migrate
+
+### Run 
+    python manage.py runserver
+
+### Create a new app
+    mkdir api
+    cd api
+    django-admin startapp task    #compare project structure with linker_srv
+* [Python Packages](https://docs.python.org/2/tutorial/modules.html#packages)
+
+### Model [Doc](https://docs.djangoproject.com/en/1.11/topics/db/models/)
+    from django.db import models
+    class Task(models.Model):
+        """task model"""
+        title = models.CharField(max_length=200)
+        description = models.TextField(blank=True)
+        created = models.DateTimeField(auto_now=True)
+        is_completed = models.BooleanField(default=False)
+
+        class Meta:
+            db_table = "task"
+
+### Install app via settings
+    INSTALLED_APPS = (
+        ....
+        'api.task',
+        )
+
+### Database [Doc](https://docs.djangoproject.com/en/1.11/topics/migrations/)
+    python manage.py makemigrations task  #note: migration files
+    python manage.py migrate #apply to the database
+    
+### Check database structure
+    #
+    # rename table name
+
+
+### Create simple view [Doc](https://docs.djangoproject.com/en/1.11/topics/http/views/)
+    from django.http import HttpResponse
+    def index(request):
+        return HttpResponse("hello django")
+
+### Mapping URL [Doc](https://docs.djangoproject.com/en/1.11/topics/http/urls/)
+    touch urls.py
+
+    from django.conf.urls import url
+    from . import views
+    urlpatterns = [
+        url(r'^$', views.index, name='index'),
+        ]
+
+### Include in main urls
+     url(r'', include('api.task.urls',namespace='task')),
+
+
+## Django admin [Doc](https://docs.djangoproject.com/en/1.11/ref/contrib/admin/)
+
+### Create admin user
+    python manage.py createsuperuser
+
+
+### Register a model
+    admin.site.register(Task)   #admin.py
+
+
+
+## [Django REST framework](http://www.django-rest-framework.org/)
+* [REST](https://zh.wikipedia.org/wiki/REST)
+* [Official Quickstart](http://www.django-rest-framework.org/tutorial/quickstart/)
+
+
+### Install
+    pip install djangorestframework
+
+### Settings
+    INSTALLED_APPS = (
+    ...
+    'rest_framework',
+    )
+
+    REST_FRAMEWORK = {
+        'DEFAULT_PERMISSION_CLASSES': [
+            'rest_framework.permissions.IsAdminUser',
+        ],
+        'PAGE_SIZE': 10
+    }
+
+### Django REST Framework Bulk [Doc](https://github.com/miki725/django-rest-framework-bulk)
+    pip install djangorestframework-bulk
+
+
+### Create View
+    from rest_framework_bulk import BulkModelViewSet
+    from api.task.models import Task
+    from api.task.serializers import TaskSerializer
+
+    class TaskView(BulkModelViewSet):
+        queryset = Task.objects.all()
+        serializer_class = TaskSerializer
+
+### Create serializers.py
+    from api.task.models import *
+    from rest_framework.serializers import ListSerializer, ModelSerializer
+
+    class TaskSerializer(ModelSerializer):
+        class Meta:
+            model = Task
+            list_serializer_class = ListSerializer
+            fields = '__all__'
+
+### Register URL
+    from rest_framework_bulk.routes import BulkRouter
+    from api.task.views import TaskView
+
+    router = BulkRouter()
+    router.register(r'task', TaskView,base_name='task')
+    urlpatterns = urlpatterns + router.urls
+
+### Testing
+
+
+### Switch Database to mysql [Doc](https://docs.djangoproject.com/en/1.11/ref/databases/)
+    pip install mysqlclient
+
+    #edit settings
+    import pymysql; 
+    pymysql.install_as_MySQLdb()
+
+    #database configurations
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'task',
+        'USER': 'root',
+        'PASSWORD': 'abc.123',
+        'HOST': 'XXXXXXXXXX',
+        'PORT': '3306',
+    }
+
+    #migration 
+
+
+
+
+
+
+
+

+ 3 - 0
api/task/admin.py

@@ -1,3 +1,6 @@
 from django.contrib import admin
 
 # Register your models here.
+from api.task.models import Task
+
+admin.site.register(Task)

+ 25 - 0
api/task/migrations/0002_auto_20170604_0220.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10 on 2017-06-04 02:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('task', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='task',
+            name='description',
+            field=models.TextField(blank=True),
+        ),
+        migrations.AlterField(
+            model_name='task',
+            name='title',
+            field=models.CharField(max_length=300),
+        ),
+    ]

+ 4 - 2
api/task/models.py

@@ -1,3 +1,5 @@
+# coding=utf-8
+
 from __future__ import unicode_literals
 
 from django.db import models
@@ -5,8 +7,8 @@ from django.db import models
 # Create your models here.
 class Task(models.Model):
     """task model"""
-    title = models.CharField(max_length=200)
-    # description = models.TextField(blank=True)
+    title = models.CharField(max_length=100,verbose_name="标题")
+    description = models.TextField(blank=True)
     created = models.DateTimeField(auto_now=True)
     is_completed = models.BooleanField(default=False)
 

+ 8 - 0
api/task/serializers.py

@@ -0,0 +1,8 @@
+from api.task.models import *
+from rest_framework.serializers import ListSerializer, ModelSerializer
+
+class TaskSerializer(ModelSerializer):
+    class Meta:
+        model = Task
+        list_serializer_class = ListSerializer
+        fields = '__all__'

+ 12 - 0
api/task/urls.py

@@ -0,0 +1,12 @@
+from django.conf.urls import url
+from . import views
+from rest_framework_bulk.routes import BulkRouter
+from api.task.views import TaskView
+
+router = BulkRouter()
+router.register(r'task', TaskView,base_name='task')
+urlpatterns = [
+    url(r'^$', views.index, name='index'),
+]
+
+urlpatterns = urlpatterns + router.urls

+ 15 - 0
api/task/views.py

@@ -1,3 +1,18 @@
 from django.shortcuts import render
 
 # Create your views here.
+
+from django.http import HttpResponse
+
+def index(request):
+    return HttpResponse("hello django")
+
+
+from rest_framework_bulk import BulkModelViewSet
+from api.task.models import Task
+from api.task.serializers import TaskSerializer
+
+
+class TaskView(BulkModelViewSet):
+    queryset = Task.objects.all()
+    serializer_class = TaskSerializer

BIN
db.sqlite3


+ 20 - 7
todo/settings.py

@@ -15,7 +15,6 @@ import os
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
-
 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
 
@@ -27,6 +26,8 @@ DEBUG = True
 
 ALLOWED_HOSTS = []
 
+import pymysql;
+pymysql.install_as_MySQLdb()
 
 # Application definition
 
@@ -38,6 +39,7 @@ INSTALLED_APPS = [
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'api.task',
+    'rest_framework',
 ]
 
 MIDDLEWARE = [
@@ -50,6 +52,13 @@ MIDDLEWARE = [
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
 ]
 
+REST_FRAMEWORK = {
+    # 'DEFAULT_PERMISSION_CLASSES': [
+    #     'rest_framework.permissions.IsAdminUser',
+    # ],
+    'PAGE_SIZE': 10
+}
+
 ROOT_URLCONF = 'todo.urls'
 
 TEMPLATES = [
@@ -70,18 +79,24 @@ TEMPLATES = [
 
 WSGI_APPLICATION = 'todo.wsgi.application'
 
-
 # Database
 # https://docs.djangoproject.com/en/1.10/ref/settings/#databases
 
 DATABASES = {
+    # 'default': {
+    #     'ENGINE': 'django.db.backends.sqlite3',
+    #     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+    # }
     'default': {
-        'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'todo1',
+        'USER': 'root',
+        'PASSWORD': 'abc.123',
+        'HOST': '192.168.1.7',
+        'PORT': '32769',
     }
 }
 
-
 # Password validation
 # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
 
@@ -100,7 +115,6 @@ AUTH_PASSWORD_VALIDATORS = [
     },
 ]
 
-
 # Internationalization
 # https://docs.djangoproject.com/en/1.10/topics/i18n/
 
@@ -114,7 +128,6 @@ USE_L10N = True
 
 USE_TZ = True
 
-
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/1.10/howto/static-files/
 

BIN
todo/settings.pyc


+ 2 - 1
todo/urls.py

@@ -13,9 +13,10 @@ Including another URLconf
     1. Import the include() function: from django.conf.urls import url, include
     2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
 """
-from django.conf.urls import url
+from django.conf.urls import url, include
 from django.contrib import admin
 
 urlpatterns = [
     url(r'^admin/', admin.site.urls),
+    url(r'', include('api.task.urls', namespace='task')),
 ]

BIN
todo/urls.pyc