2016-09-01から1ヶ月間の記事一覧
サーチ機能をつける products/views.py を編集する。 class ProductListView(ListView): ... def get_queryset(self, *args, **kwargs): qs = super(ProductListView, self).get_queryset(*args, **kwargs) return qs ... これは、get_queryメソッドを上書き…
画像のアップロードについて models.py に画像アップ用のclassを作成する とりあえず、以下のような感じでシンプルに書いてみる。 ... class ProductImage(models.Model): product = models.ForeignKey(Product) image = models.ImageField(upload_to='produ…
Product Detailのレイアウトを整える。 product_detail.html をbootstarp風に修正する。 {% extends "base.html" %} {% block content %} <div class='row'> <div class='col-sm-8'> <h2>{{ object.title }}</h2> <p class='lead'>{{ object.description }}</p> </div> <div class='col-sm-4'> <h3>{{ object.price }…</h3></div></div>
Variationsの、Post Save Signal http://127.0.0.1:8000/products/2/ については、まだvariationが登録されていないため、選択肢が空欄になっていると思います。 Signalの公式ドキュメント: Signals | Django documentation | Django その中でも、post_save…
Product Variationのmodelを作る Variationは、例えば、iphone7 16GB,32GBとか言うように、同じ商品で、別々のvariationがある場合 * products/models.py に、以下を追加する。 class Variation(models.Model): product = models.ForeignKey(Product) title …
models.Mangerを使った、model classの作成 activeなリストのみを表示したい。 products/models.py を以下のように設定する。 class ProductQuerySet(models.query.QuerySet): def active(self): return self.filter(active=True) class ProductManager(mode…
Model Instanceへの、Linksをurls.py のnameを使ってやってみる。さらにget_absolute_url がbestpracticeのよう。 templates/products/product_list.html に試しに、linkを挿入してみる。 {% for object in object_list %} <tr> <td>{{ object.id }}</td> <td><a href='/products/{{ object.id }}'>{{ object.title</a></td></tr>…
List Viewを作成する このあたりを参照にしながら作成していく。 Generic display views | Django documentation | Django products/views.py ListViewをimport, class でListViewを継承、modelに,models.py からのmodelclassを代入 + from django.views.gen…
template作成 と viewの設定(cbv とfunction viewの違い) ひとまず、products/templates/products/product_detail.htmlのフォルダとファイルを作成する product_detail.html 試してみる。 {% extends "base.html" %} {% block content %} {{ object.title }…
Appフォルダ内の Urls.py を設定する まず、projectrootのurls.py の設定をする。 rlpatterns = [ url(r'^products/', include('products.urls')), ] ここでは、$マークをつけないように注意。 products/urls.py を新規作成する。そして、元のurls.pyの内容…
今回の動画 Coding for Entrepreneurs Class Based View を使って見る 公式サイトは、ここら辺りを参照 Built-in class-based generic views | Django documentation | Django products/views.py を編集していく from django.views.generic import DetailVie…
Productのロードマップを考える modelはなんとなくこんな感じなのかなと予想。ただ、違う可能性も大いにあり。 *サイト概要はこんな感じ?? まずは、startapp でproducts フォルダを作成する ``` python manage.py startapp products * products/models.py …
元の動画 Coding for Entrepreneurs trydjango1.8 → ecommerce2にファイル名とか諸々を変更していく フォルダ名変更に伴うそのフォルダを参照しているファイル内にある文字列を変更する。 1つ1つ検索して置き換えは、面倒なので、cmd+shift+f で、ディレク…
今回の動画 Coding for Entrepreneurs Coding for Entrepreneurs Setup Previous Project githubより前回のtrydjango1.8をcloneしてくる あと、'sudo pip install requests[security]' でsecurity関連のライブラリをinstallしておく *django ==1.8.4 にupgra…
独自ドメインの設定 settings/production.py にドメインネームを追加していく ALLOWED_HOSTS = [ここに、www.ドメイン、ドメイン を追加する] error pageのtemplateを作成する。 400.html 404.html 403.html 500.html error pageの公式ドキュメントはこちら…
Static Settingsをちょっと修正する webfactionに、media フォルダを追加する。 Create a New application で、 name mvpland_static (他の案件と区別するため) appcategory static apptype static only url media/ settings/production.pyのmedia,static …
Install PIP + Migrate + Static Settings まずPIPをinstallする。と思ったけど、3.4からは標準でpipだからinstallする必要なし! ※2.7の場合 * $HOME/lib/にpython2.7 のdirを作成する。p mkdir -p $HOME/lib/python2.7 easy_install-2.y pip -p, --parents…
FTPを使ったproduction settings filezilla を利用して、sftpで接続する。 この辺りのサイトが参照しやすいと思います。 FileZilla の設定(Mac OS X の場合) - KAGOYA Internet Routing sshで、port22でアクセスしました。 デフォで入っている、djangoのproj…
SSHを使ってwebfactionにデプロイの準備をする webfaction にログインする。 http://ユーザー名.webfactional.com/ が割り当てられている。 DOMAINES/WEBSITES→Websites website の一覧が出てくる。 DOMAINES/WEBSITES→applications で、アプリ一覧が出てく…
開発段階ごとのSettings.py の設定方法 webfaction を利用する(会員登録などを済ませる) settings.py を設定していく ローカル(開発環境)では、DEBUG=True 運用時には、DEBUG = Falseにしたい。 settings フォルダを作る(projectルート?settings.pyがあ…
参照サイト QuerySet API reference | Django documentation | Django この辺のquerysetの使い方も参考になるとのこと。 Coding for Entrepreneurs DjangoのQuerySet の基本を学ぶ 多分、querysetは、model,viewとかで使われるんだろうな。 まず、試しに、qu…
認証済みユーザ向けのコンテンツの表示方法 まず、サイト全体のbodyが大きすぎるため、その大きさを調整する。 navbar-static-top.css body { min-height: 1000px; } ... ここらで一旦、collectstatic コマンドを打つ about.html を作っていなかったので、te…
Font Awesomeを使ったIconの挿入 fonrt awesome にアクセス Font Awesome, the iconic font and CSS toolkit 好きなアイコンをクリック→css のコードをコピー これだけだと反映されない。 ... <div class="col-sm-3"> <p class='lead text-align-center'>Fast</p> <i class="fa fa-ship" aria-hidden="true"></i> </div> ... bootstrapに読み込ませる。 オススメは、BootstrapC…
Logo Image in Navbar navbarにlogo imageを挿入する 忘れずに、load staticfilesも挿入する。 navbar.html {% load staticfiles %} ... <a class="navbar-brand" href="{% url 'home' %}"><img src="{% static 'img/logo_design_lab.png'%}" /></a> ... Promo Video & Images youtube動画の埋め込みが可能(ブラックボックスも削除してOK) home.html ...
ホームページを修正する base.html → home.html にjumbotronの編集のコードを移す。 {% block jumbotron %} <div class="jumbotron"> <div class="container"> <div class="row"> <div class="col-sm-6"> <h1>Design Learning Lab</h1> <p>コメント1</p> <pコメント</p> <p> </p></pコメント</p></div></div></div></div>
参照サイト bootstrapのformについては、こちらのサイトが非常にわかりやすかったです! designup.jp Navbarを利用したLogin formを作成 navbar.html にフォームタグを追加する。 class=navbar-form→navbarのフォーム class=navbar-right→navbarの右側(右寄…
Navbarの、認証済みユーザー向けlink navbar.html の、dropdownリストの箇所をコメントアウトする。 ... navbar-rightのあたりを自分用に以下のような感じでカスタマイズする。 とりあえず hrefは空欄でもOK。{{request.user}}などで、パラメーターの挿入も…
Django Login URL から Custom URLへの遷移 現在はloginすると、accounts/profile/ につながるようになっている。 ただし、accounts/profile/はurlを用意していないので、urlを変えるか、accounts/profile/を作るかのどっちか。 settings.py にLOGIN_REDIREC…
参照サイト django-registrationの公式サイト? django-registration-redux 1.4 documentation — django-registration-redux 1.4 documentation django-registrationのgithubのサイト GitHub - macropin/django-registration: django-registration (redux) n…
Home Pageのスタイルを整えていく newsletter/views.py contact のtemplatesの、forms.html を修正していく まずは、'{% extends "base.html" %}' を追加する 次に、base.htmlのうち、formsを挿入したい箇所を決める。 今回の場合は、block content(content…