6. MTV とは
Django appears to be a MVC
framework, but you call the
Controller the “view”, and the
View the “template”. How come
you don’t use the standard names?¶
(https://docs.djangoproject.com/en/dev/faq/general/ より)
23. get_all_related_objects_with_model
Returns a list of (related-object, model) pairs. Similar to
get_fields_with_model().
Related オブジェクトのペアのリストを返します
例:
[(<RelatedObject: common:sandwich related to item_ptr>, None),
(<RelatedObject: common:onigiri related to item_ptr>, None)]
24. get_parent_list
Returns a list of all the ancestor of this model as a list. Useful for
determining if something is an ancestor, regardless of lineage.
全てのこのモデルの親(先祖)のリストを返します
(私の実機では list ではなく set オブジェクトでした)
例:
set([<class 'common.models.Item'>])
33. Mako
<%inherit file="base.html"/>
<%
rows = [[v for v in range(0,10)] for row in range(0,10)]
%>
<table>
% for row in rows:
${makerow(row)}
% endfor
</table>
<%def name="makerow(row)">
<tr>
% for name in row:
<td>${name}</td>
% endfor
</tr>
</%def>
40. Django の XML ベーステンプレートエンジンに対する 評価
②
そう、もう一つあります:
人間に XML を編集させるなんて、
サディスティック でしかありません!
http://docs.djangoproject.jp/ja/latest/topics/templates.html
70. まずは API を実装
common/api.py
from tastypie.resources import ModelResource
from common.models import Onigiri
class OnigiriResource(ModelResource):
class Meta:
queryset = Onigiri.objects.all()
resource_name = 'onigiri
71. Urlsの編集
ecsite/urls.py
from tastypie.api import Api
from django.contrib import admin
admin.autodiscover()
onigiri_resource = OnigiriResource()
v1_api = Api(api_name='v1')
v1_api.register(OnigiriResource())
urlpatterns = patterns('',
url(r'^api/', include(onigiri_resource.urls)),
)
73. しかしこの状態では
However, if you try sending a POST/PUT/DELETE to the resource,
you find yourself getting “401 Unauthorized” errors. For safety,
Tastypie ships with the authorization class (“what are you allowed to do”) set to
ReadOnlyAuthorization. This makes it safe to expose on the web, but prevents
us from doing POST/PUT/DELETE. Let’s enable those:
http://django-tastypie.readthedocs.org/en/latest/tutorial.html
POST/PUT/DELETE が使用できない
→ つまり API として利用するには取得しか出来ない!
74. 認証・権限の実装
common/api.py
from tastypie.authentication import OAuthAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.resources import ModelResource
from common.models import Onigiri
class OnigiriResource(ModelResource):
class Meta:
queryset = Onigiri.objects.all()
resource_name = 'onigiri
authentication = OAuthAuthentication()
authorization = DjangoAuthorization