Django: Difference between revisions
Line 40: | Line 40: | ||
"Projects vs. apps" - "What’s the difference between a project and an app? An app is a web application that does something – e.g., a blog system, a database of public records or a small poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects." | "Projects vs. apps" - "What’s the difference between a project and an app? An app is a web application that does something – e.g., a blog system, a database of public records or a small poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects." | ||
So, the outer mysite is "a collection of configuration and apps for a particular website" ... maybe the inner mysite is one of the "multiple apps"? Something like a main app? Or can | So, the outer mysite is "a collection of configuration and apps for a particular website" ... maybe the inner mysite is one of the "multiple apps"? Something like a main app? Or can it be deleted? |
Revision as of 2022-06-14T23:07:51
Models
Migrations
Example 1
- change model type e.g. Char to Integer : psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: ""
- alter field name in model ...try to delete field ...errors...
- to fix, try to rename, remove ... delete col by hand using psql, delete migrations, recreate migration ...
- problems: stuck in errors psycopg2.errors.DuplicateColumn: column "ccc" of relation "rrr" already exists
Example 2
- change of field to unique can result in "DETAIL: Key (id....)=() is duplicated."
Example 3
- if changing CharField to Unique the migration maybe does not convert the emty values to None?NULL and then one gets problems like: https://stackoverflow.com/questions/17257031/django-unique-null-and-blank-charfield-giving-already-exists-error-on-admin-p
Tutorial
https://docs.djangoproject.com/en/4.0/intro/tutorial01/
"We’ll assume you have Django installed already. " - linking to https://docs.djangoproject.com/en/4.0/intro/install/ - venv isn't mentioned, but maybe it is better to do that and not pollute the OS.
django-admin startproject mysite
Shouln't it be myproject instead of mysite, if the command is "startproject"?
The command creates:
mysite/ manage.py mysite/
"The outer mysite/ root directory is a container for your project" - really? What if one had that before (e.g. for data or the venv) and performed "django-admin startproject" within that?
"The inner mysite/ directory is the actual Python package for your project." - the other is the container, this one "the actual Python package for your project".
"June 01, 2022 - 15:50:53" - why this weird data format? How about ISO 8601?
Creating the Polls app Now that your environment – a “project” – is set up, you’re set to start doing work.
Set up are: 1) a venv 2) "a container for your project" 3) "the actual Python package for your project".
"Projects vs. apps" - "What’s the difference between a project and an app? An app is a web application that does something – e.g., a blog system, a database of public records or a small poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects."
So, the outer mysite is "a collection of configuration and apps for a particular website" ... maybe the inner mysite is one of the "multiple apps"? Something like a main app? Or can it be deleted?