Skip to content

Commit 89e1174

Browse files
committed
db for tutorial
1 parent 21be5bd commit 89e1174

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

db.sqlite3

40 KB
Binary file not shown.

doc/source/index.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ Then run the test application::
6767
Quit the server with CTRL-BREAK.
6868

6969

70-
Handle excel file upload
71-
+++++++++++++++++++++++++
70+
Handle excel file upload and download
71+
++++++++++++++++++++++++++++++++++++++
7272

73-
If you open your browser and visit http://localhost:8000/upload, you shall see this upload form:
73+
This example shows how to process uploaded excel file and how to make data download as an excel file. Open your browser and visit http://localhost:8000/upload, you shall see this upload form:
7474

7575
.. image :: upload-form.png
7676
77+
Choose an excel sheet, for example an xls file, and press "Submit". You will get a csv file for download.
78+
79+
.. image :: download-file.png
80+
7781
Please open the file **polls/views.py** and focus on the following code section::
7882

7983
class UploadFileForm(forms.Form):
@@ -90,10 +94,12 @@ Please open the file **polls/views.py** and focus on the following code section:
9094
form = UploadFileForm()
9195
return render_to_response('upload_form.html', {'form': form}, context_instance=RequestContext(request))
9296

93-
**UploadFileForm** is html widget for file upload form in the html page. Then look down at **filehandle**. It is an instance of either ExcelInMemoryUploadedFile or TemporaryUploadedExcelFile, which inherit ExcelMixin and hence have a list of conversion methods to call, such as get_sheet, get_array, etc.
97+
**UploadFileForm** is html widget for file upload form in the html page. Then look down at **filehandle**. It is an instance of either ExcelInMemoryUploadedFile or TemporaryUploadedExcelFile, which inherit ExcelMixin and hence have a list of conversion methods to call, such as get_sheet, get_array, etc. :meth:`~django_excel.make_response` converts :class:`~pyexcel.Sheet` instance obtained via :meth:`~django_excel.ExcelMixin.get_sheet` into a csv file for download. Please feel free to change those functions according to :ref:`the mapping table <data-types-and-its-conversion-funcs>`.
9498

9599
... to be continued ..
96100

101+
.. _data-types-and-its-conversion-funcs:
102+
97103
All supported data types
98104
--------------------------
99105

@@ -184,6 +190,8 @@ API Reference
184190
Response methods
185191
-----------------
186192

193+
.. automodule:: django_excel
194+
187195
.. method:: make_response(pyexcel_instance, file_type, status=200)
188196

189197
:param pyexcel_instance: pyexcel.Sheet or pyexcel.Book

polls/admin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from django.contrib import admin
2-
2+
from models import Question, Choice
33
# Register your models here.
4+
admin.site.register(Question)
5+
admin.site.register(Choice)

polls/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
from django.db import models
22

33
# Create your models here.
4+
class Question(models.Model):
5+
question_text = models.CharField(max_length=200)
6+
pub_date = models.DateTimeField('date published')
7+
8+
9+
class Choice(models.Model):
10+
question = models.ForeignKey(Question)
11+
choice_text = models.CharField(max_length=200)
12+
votes = models.IntegerField(default=0)

0 commit comments

Comments
 (0)