Djangoroidの奮闘記

python,django,angularJS1~三十路過ぎたプログラマーの奮闘記

2016-09-01から1ヶ月間の記事一覧

Django e-commerce part18 Search Query

サーチ機能をつける products/views.py を編集する。 class ProductListView(ListView): ... def get_queryset(self, *args, **kwargs): qs = super(ProductListView, self).get_queryset(*args, **kwargs) return qs ... これは、get_queryメソッドを上書き…

Django e-commerce part17 Image Uploads

画像のアップロードについて models.py に画像アップ用のclassを作成する とりあえず、以下のような感じでシンプルに書いてみる。 ... class ProductImage(models.Model): product = models.ForeignKey(Product) image = models.ImageField(upload_to='produ…

Django e-commerce part16 Product Detail Layout

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>

Django e-commerce part15 Post Save Signals for Variations

Variationsの、Post Save Signal http://127.0.0.1:8000/products/2/ については、まだvariationが登録されていないため、選択肢が空欄になっていると思います。 Signalの公式ドキュメント: Signals | Django documentation | Django その中でも、post_save…

Django e-commerce part14 Product Variations

Product Variationのmodelを作る Variationは、例えば、iphone7 16GB,32GBとか言うように、同じ商品で、別々のvariationがある場合 * products/models.py に、以下を追加する。 class Variation(models.Model): product = models.ForeignKey(Product) title …

Django e-commerce part13 Model Managers

models.Mangerを使った、model classの作成 activeなリストのみを表示したい。 products/models.py を以下のように設定する。 class ProductQuerySet(models.query.QuerySet): def active(self): return self.filter(active=True) class ProductManager(mode…

Django e-commerce part12 Using Links for Model Instances

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>…

eCommerce2 part11 ListView

List Viewを作成する このあたりを参照にしながら作成していく。 Generic display views | Django documentation | Django products/views.py ListViewをimport, class でListViewを継承、modelに,models.py からのmodelclassを代入 + from django.views.gen…

eCommerce 2 part10 Add HTML Template

template作成 と viewの設定(cbv とfunction viewの違い) ひとまず、products/templates/products/product_detail.htmlのフォルダとファイルを作成する product_detail.html 試してみる。 {% extends "base.html" %} {% block content %} {{ object.title }…

eCommerce 2 part9 Urls within Django App

Appフォルダ内の Urls.py を設定する まず、projectrootのurls.py の設定をする。 rlpatterns = [ url(r'^products/', include('products.urls')), ] ここでは、$マークをつけないように注意。 products/urls.py を新規作成する。そして、元のurls.pyの内容…

e-commerce 2 part7 Products App

今回の動画 Coding for Entrepreneurs Class Based View を使って見る 公式サイトは、ここら辺りを参照 Built-in class-based generic views | Django documentation | Django products/views.py を編集していく from django.views.generic import DetailVie…

e-commerce2 part6 Product Roadmap

Productのロードマップを考える modelはなんとなくこんな感じなのかなと予想。ただ、違う可能性も大いにあり。 *サイト概要はこんな感じ?? まずは、startapp でproducts フォルダを作成する ``` python manage.py startapp products * products/models.py …

django e-commerce2: 5 Try Django 1.8 to eCommerce 2

元の動画 Coding for Entrepreneurs trydjango1.8 → ecommerce2にファイル名とか諸々を変更していく フォルダ名変更に伴うそのフォルダを参照しているファイル内にある文字列を変更する。 1つ1つ検索して置き換えは、面倒なので、cmd+shift+f で、ディレク…

django "ecommerce-2" 3 Requirements~ 4 Setup Previous Project

今回の動画 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…

django備忘録32 URLの設定

独自ドメインの設定 settings/production.py にドメインネームを追加していく ALLOWED_HOSTS = [ここに、www.ドメイン、ドメイン を追加する] error pageのtemplateを作成する。 400.html 404.html 403.html 500.html error pageの公式ドキュメントはこちら…

django備忘録31 Fix Static Settings

Static Settingsをちょっと修正する webfactionに、media フォルダを追加する。 Create a New application で、 name mvpland_static (他の案件と区別するため) appcategory static apptype static only url media/ settings/production.pyのmedia,static …

django備忘録30 Install PIP + Migrate + Static Settings

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…

django備忘録29 FTP for Production Settings

FTPを使ったproduction settings filezilla を利用して、sftpで接続する。 この辺りのサイトが参照しやすいと思います。 FileZilla の設定(Mac OS X の場合) - KAGOYA Internet Routing sshで、port22でアクセスしました。 デフォで入っている、djangoのproj…

django備忘録28 Using SSH with Webfaction

SSHを使ってwebfactionにデプロイの準備をする webfaction にログインする。 http://ユーザー名.webfactional.com/ が割り当てられている。 DOMAINES/WEBSITES→Websites website の一覧が出てくる。 DOMAINES/WEBSITES→applications で、アプリ一覧が出てく…

django備忘録27 Settings for Different Environments

開発段階ごとのSettings.py の設定方法 webfaction を利用する(会員登録などを済ませる) settings.py を設定していく ローカル(開発環境)では、DEBUG=True 運用時には、DEBUG = Falseにしたい。 settings フォルダを作る(projectルート?settings.pyがあ…

django備忘録26 QuerySet Basics

参照サイト QuerySet API reference | Django documentation | Django この辺のquerysetの使い方も参考になるとのこと。 Coding for Entrepreneurs DjangoのQuerySet の基本を学ぶ 多分、querysetは、model,viewとかで使われるんだろうな。 まず、試しに、qu…

django備忘録25 Content for Authenticated Users

認証済みユーザ向けのコンテンツの表示方法 まず、サイト全体のbodyが大きすぎるため、その大きさを調整する。 navbar-static-top.css body { min-height: 1000px; } ... ここらで一旦、collectstatic コマンドを打つ about.html を作っていなかったので、te…

django備忘録24 Icons with Font Awesome

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…

django備忘録23 Logo Image in Navbar + Promo Video & Images

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 ...

django備忘録22 Styling MVP Landing Part 3

ホームページを修正する 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>

django備忘録21 Login Form in Bootstrap Navbar

参照サイト bootstrapのformについては、こちらのサイトが非常にわかりやすかったです! designup.jp Navbarを利用したLogin formを作成 navbar.html にフォームタグを追加する。 class=navbar-form→navbarのフォーム class=navbar-right→navbarの右側(右寄…

django備忘録20 Authentication Links in the Navbar

Navbarの、認証済みユーザー向けlink navbar.html の、dropdownリストの箇所をコメントアウトする。 ... navbar-rightのあたりを自分用に以下のような感じでカスタマイズする。 とりあえず hrefは空欄でもOK。{{request.user}}などで、パラメーターの挿入も…

django備忘録19 Update Django Login URL to Custom URL

Django Login URL から Custom URLへの遷移 現在はloginすると、accounts/profile/ につながるようになっている。 ただし、accounts/profile/はurlを用意していないので、urlを変えるか、accounts/profile/を作るかのどっちか。 settings.py にLOGIN_REDIREC…

django備忘録18 Django Registration [Redux]

参照サイト 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…

django備忘録17 Styling MVP Landing Part 2

Home Pageのスタイルを整えていく newsletter/views.py contact のtemplatesの、forms.html を修正していく まずは、'{% extends "base.html" %}' を追加する 次に、base.htmlのうち、formsを挿入したい箇所を決める。 今回の場合は、block content(content…