-
Notifications
You must be signed in to change notification settings - Fork 0
/
Further discussion with regard to Model.html
288 lines (207 loc) · 13.9 KB
/
Further discussion with regard to Model.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html lang="en"><head>
<title>Further discussion with regard to Model</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="Further%20discussion%20with%20regard%20to%20Model_files/style.css" media="all" type="text/css" rel="stylesheet">
<style type="text/css">#yddContainer{display:block;font-family:Microsoft YaHei;position:relative;width:100%;height:100%;top:-4px;left:-4px;font-size:12px;border:1px solid}#yddTop{display:block;height:22px}#yddTopBorderlr{display:block;position:static;height:17px;padding:2px 28px;line-height:17px;font-size:12px;color:#5079bb;font-weight:bold;border-style:none solid;border-width:1px}#yddTopBorderlr .ydd-sp{position:absolute;top:2px;height:0;overflow:hidden}.ydd-icon{left:5px;width:17px;padding:0px 0px 0px 0px;padding-top:17px;background-position:-16px -44px}.ydd-close{right:5px;width:16px;padding-top:16px;background-position:left -44px}#yddKeyTitle{float:left;text-decoration:none}#yddMiddle{display:block;margin-bottom:10px}.ydd-tabs{display:block;margin:5px 0;padding:0 5px;height:18px;border-bottom:1px solid}.ydd-tab{display:block;float:left;height:18px;margin:0 5px -1px 0;padding:0 4px;line-height:18px;border:1px solid;border-bottom:none}.ydd-trans-container{display:block;line-height:160%}.ydd-trans-container a{text-decoration:none;}#yddBottom{position:absolute;bottom:0;left:0;width:100%;height:22px;line-height:22px;overflow:hidden;background-position:left -22px}.ydd-padding010{padding:0 10px}#yddWrapper{color:#252525;z-index:10001;background:url(chrome-extension://eopjamdnofihpioajgfdikhhbobonhbb/ab20.png);}#yddContainer{background:#fff;border-color:#4b7598}#yddTopBorderlr{border-color:#f0f8fc}#yddWrapper .ydd-sp{background-image:url(chrome-extension://eopjamdnofihpioajgfdikhhbobonhbb/ydd-sprite.png)}#yddWrapper a,#yddWrapper a:hover,#yddWrapper a:visited{color:#50799b}#yddWrapper .ydd-tabs{color:#959595}.ydd-tabs,.ydd-tab{background:#fff;border-color:#d5e7f3}#yddBottom{color:#363636}#yddWrapper{min-width:250px;max-width:400px;}</style>
<script src="Further%20discussion%20with%20regard%20to%20Model_files/a.js" async="" type="text/javascript"></script><script src="Further%20discussion%20with%20regard%20to%20Model_files/analytics.js" async=""></script><script src="Further%20discussion%20with%20regard%20to%20Model_files/embed.js" async="" type="text/javascript"></script></head>
<body>
<header>
<section class="logo">
<h1><a href="http://webcoursify.github.io/">WebDev Course</a></h1>
<h2 class="subheader">by Tyrone Cheung</h2>
</section>
<nav id="nav">
<ul>
<li><a href="http://webcoursify.github.io/about">ReadMe</a></li>
<li><a href="http://webdemo.zhangty.me/">Project Demo</a></li>
<li><a href="http://webcoursify.github.io/project_code">Download Project</a></li>
<li><a href="http://eepurl.com/_YOyb">Subscribe update</a></li>
<li><a href="mailto:firstprayer.zhang@gmail.com">Contact</a></li>
</ul>
</nav>
</header>
<div class="container">
<div class="content">
<article>
<h1>Further discussion with regard to Model</h1>
<h5>Last modified: 12-23-2014</h5>
<p>We present several discussions here.</p>
<h4 id="index">1. Index</h4>
<p>Index is some kind of additional data structure used for faster data
retrieval. The most widely used index type is BTree, or some variants of
it. To say it in a simple way, BTree puts nodes with smaller value on
the left and nodes with larger value on the right, so it puts all rows
in order with respect to specific field(s). For example, an index with
respect to the <code>id</code> field will put all rows in the ascending order of id, while an index with respect the <code>age</code> will put all rows in the ascending order or age, which is different from the order with respect to id. </p>
<p>All primary keys and foreign keys are accompanied with index. We can
define our own index on one or more than one fields. The advantage here
is we can search faster. If we want users with age=18 we can do this by
searching a very small part of the index we have on the age field. If we
do not, we’ll need to scan the whole table. However, the disadvantage
is we need to pay the maintainence cost for this structure when we need
to insert/update rows. </p>
<h4 id="you-see-that-codedeletedcode-field">2. You see that <code>deleted</code> field?</h4>
<p>When I first see such a field I was confused, as you might be now.
What’s it for? Sounds like a field used to mark whether a row is deleted
or not. If so, why do we need this field? Why not just delete the row,
but border to keep the row and mark it as deleted? </p>
<p>There’re some discussions around this and some people might say this
is judgement call. Here’s Pros and Cons I could think of or find online:</p>
<p>Pros:</p>
<ul>
<li>Doing so makes it possible to restore the data</li>
<li>It’s usually faster to update a field than actually deleting a row</li>
<li>…</li>
</ul>
<p>Cons:</p>
<ul>
<li>It’s easier to introduce bugs in the program. People might just forget to add ‘deleted=0’ condition in the SQL, for exmaple</li>
<li>The table will be larger, so data retrieval may be slower</li>
<li>…</li>
</ul>
<p>It might indeed be a judgement call and I just put it here for
demonstration. You can choose whether or not use this strategy when
you’re desgining new tables in later courses (but please keep the
original tables in this way, because our test cases in based on this).</p>
</article>
<div id="disqus_thread"><iframe verticalscrolling="no" horizontalscrolling="no" src="Further%20discussion%20with%20regard%20to%20Model_files/a.html" style="width: 100% ! important; border: medium none ! important; overflow: hidden ! important; height: 614px ! important;" title="Disqus" tabindex="0" scrolling="no" allowtransparency="true" data-disqus-uid="2" id="dsq-2" frameborder="0" width="100%"></iframe></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'webcoursify'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</div>
<aside class="sidebar">
<section class="module">
<h2 style="margin-left: 24px;">FullStack Web Development</h2>
<ul class="lesson-list chapter-list">
<li data-url="/content/0-Preface.html">
<a href="http://webcoursify.github.io/content/0-Preface.html">
<span class="lesson-title">1 - Preface</span>
</a>
</li>
<li data-url="/content/1-DjangoBasic">
<a href="http://webcoursify.github.io/content/1-DjangoBasic">
<span class="lesson-title">2 - Django Basic</span>
</a>
<ul class="section-list">
<li data-url="/content/1-DjangoBasic/1-ClientServer.html"><a href="http://webcoursify.github.io/content/1-DjangoBasic/1-ClientServer.html">1 - Client-Server Model and MVC Design Pattern</a></li>
<li data-url="/content/1-DjangoBasic/2-DjangoMVC.html"><a href="http://webcoursify.github.io/content/1-DjangoBasic/2-DjangoMVC.html">2 - Django's MVC</a></li>
<li data-url="/content/1-DjangoBasic/3-Assignment.html"><a href="http://webcoursify.github.io/content/1-DjangoBasic/3-Assignment.html">3 - Assignment-Django Basic</a></li>
</ul>
</li>
<li data-url="/content/2-MVC-Controller">
<a href="http://webcoursify.github.io/content/2-MVC-Controller">
<span class="lesson-title">3 - Intro to Django's Controller</span>
</a>
<ul class="section-list">
<li data-url="/content/2-MVC-Controller/1-DjangoReqRes.html"><a href="http://webcoursify.github.io/content/2-MVC-Controller/1-DjangoReqRes.html">1 - Django's HttpRequest, HttpResponse, and Url dispatching</a></li>
<li data-url="/content/2-MVC-Controller/2-Assignment.html"><a href="http://webcoursify.github.io/content/2-MVC-Controller/2-Assignment.html">2 - Assignment for Implementing Controller</a></li>
</ul>
</li>
<li class="active" data-url="/content/3-MVC-Model">
<a href="http://webcoursify.github.io/content/3-MVC-Model">
<span class="lesson-title">4 - Model Layer in Django</span>
</a>
<ul class="section-list">
<li data-url="/content/3-MVC-Model/1-DjangoModel.html"><a href="http://webcoursify.github.io/content/3-MVC-Model/1-DjangoModel.html">1 - Using Model in Django</a></li>
<li class="active" data-url="/content/3-MVC-Model/2-FurtherDiscussion.html"><a href="http://webcoursify.github.io/content/3-MVC-Model/2-FurtherDiscussion.html">2 - Further discussion with regard to Model</a></li>
<li data-url="/content/3-MVC-Model/3-Assignment.html"><a href="http://webcoursify.github.io/content/3-MVC-Model/3-Assignment.html">3 - Assignments for Model</a></li>
</ul>
</li>
<li data-url="/content/4-MVC-View">
<a href="http://webcoursify.github.io/content/4-MVC-View">
<span class="lesson-title">5 - The View-User Interaction</span>
</a>
<ul class="section-list">
<li data-url="/content/4-MVC-View/2-DjangoTemplate.html"><a href="http://webcoursify.github.io/content/4-MVC-View/2-DjangoTemplate.html">1 - Template in Django</a></li>
<li data-url="/content/4-MVC-View/3-FormAjax.html"><a href="http://webcoursify.github.io/content/4-MVC-View/3-FormAjax.html">2 - Form, Ajax</a></li>
<li data-url="/content/4-MVC-View/4-RichEditor.html"><a href="http://webcoursify.github.io/content/4-MVC-View/4-RichEditor.html">3 - Using Rich Text Editor with Ajax</a></li>
<li data-url="/content/4-MVC-View/5-Assignment.html"><a href="http://webcoursify.github.io/content/4-MVC-View/5-Assignment.html">4 - Assignments for View</a></li>
</ul>
</li>
<li data-url="/content/5-Topic-User.html">
<a href="http://webcoursify.github.io/content/5-Topic-User.html">
<span class="lesson-title">6 - User Management in WebApp</span>
</a>
</li>
<li data-url="/content/6-ProjectSpecification.html">
<a href="http://webcoursify.github.io/content/6-ProjectSpecification.html">
<span class="lesson-title">7 - Capstone Project Specification</span>
</a>
</li>
<li data-url="/content/99-ExtraMaterials">
<a href="http://webcoursify.github.io/content/99-ExtraMaterials">
<span class="lesson-title">8 - Extra Tutorials</span>
</a>
<ul class="section-list">
<li data-url="/content/99-ExtraMaterials/1-IntroToGit.html"><a href="http://webcoursify.github.io/content/99-ExtraMaterials/1-IntroToGit.html">1 - Introduction to Git</a></li>
<li data-url="/content/99-ExtraMaterials/2-Deployment.html"><a href="http://webcoursify.github.io/content/99-ExtraMaterials/2-Deployment.html">2 - Deployment</a></li>
</ul>
</li>
</ul>
</section>
<footer>
Copyright 2015 Tyrone Cheung
</footer>
<footer>
<p>
<b>This course has been finished just recently, and there're a
lot of improvements pending. If you like it, or think it's useful, or
start to go through the course content, please <a href="mailto:zhangty10@gmail.com">shoot me an email</a> to let me know. Thanks!</b>
</p>
</footer>
</aside>
<!-- Bootstrap core JavaScript-->
<!-- <script src="/js/jquery-1.10.2.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/hc.js"></script> -->
<script type="text/javascript" src="Further%20discussion%20with%20regard%20to%20Model_files/jquery-2.js"></script>
<script type="text/javascript" async="" src="Further%20discussion%20with%20regard%20to%20Model_files/saved_resource.js"></script>
<script type="text/javascript" async="" src="Further%20discussion%20with%20regard%20to%20Model_files/inpage_linkid.js" id="undefined"></script>
<script type="text/javascript" async="" src="Further%20discussion%20with%20regard%20to%20Model_files/library.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l=document.getElementsByTagName("a"),t=document.createElement("textarea");for(i=0;l.length-i;i++){try{a=l[i].getAttribute("href");if(a&&a.indexOf("/cdn-cgi/l/email-protection") > -1 && (a.length > 28)){s='';j=27+ 1 + a.indexOf("/cdn-cgi/l/email-protection");if (a.length > j) {r=parseInt(a.substr(j,2),16);for(j+=2;a.length>j&&a.substr(j,1)!='X';j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}j+=1;s+=a.substr(j,a.length-j);}t.innerHTML=s.replace(/</g,"<").replace(/>/g,">");l[i].setAttribute("href","mailto:"+t.value);}}catch(e){}}}catch(e){}})();
/* ]]> */
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-57962734-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript">
var getLocation = function(href) {
var l = document.createElement("a");
l.href = href;
return l;
};
var pathname = getLocation(window.location.href).pathname;
if(pathname[pathname.length - 1] == '/')
pathname = pathname.substring(0, pathname.length - 1);
function setActive(){
var $this = $(this);
if($this.data('url') && pathname.indexOf($this.data('url')) == 0){
$(this).addClass('active');
}
}
$('ul.chapter-list li')
.each(setActive);
$('ul.section-list li')
.each(setActive);
</script>
</body></html>