django-tutorial-for-programmers
django-tutorial-for-programmers copied to clipboard
Chapter text and example code for the Django tutorial first appeared during ITHome Ironman 7
ForeignKey is a Django field for defining a many-to-one relationship. Up until Django 1.9 the ForeignKey field required **a single argument**: the model to map to. Since **Django 2.0** the...
`assets/django-admin-add.png` 在這個階段應該還不會有owner這個tag
``` class MenuItem(models.Model): store = models.ForeignKey('Store', related_name='menu_items') name = models.CharField(max_length=20) price = models.IntegerField() def __str__(self): return self.name ``` [現在models.ForeignKey的 on_delete是必要參數](https://www.valentinog.com/blog/django-missing-argument-on-delete/)
* [x] 升到 Django 2.0 * [ ] Best practices * [x] Pipenv 管理專案套件 * [x] Python Dotenv 管理環境變數 (#28) * [ ] Pytest 單元測試 (和它的一堆插件與使用技巧,例如 model mocking) * [...
Fat model and mangers, forms when suitable, thin views, trivial templates. 節錄一些 Gitter 對話 --- 壞範例: ``` python from django.db import models class Restaurant(models.Model): is_fastfood = models.BooleanField() average_price = models.IntegerField()...
https://github.com/jpadilla/django-dotenv Avoid setting environ directly (in either `~/.bashrc` or `venv/bin/activate`).