Product
init a product
MVP (Minimum viable product) is the main product development strategy. minimum dev, maximum iteration.
database principles
-
basic:
-
clear: the name of the tables, attributes must be clear
-
unique: one table for one use case, do not stock useless info
-
primary key: pk must be unique
-
-
complete
-
complete: all the import data is saved
-
searchable: data has created_date and updated_date
-
identical: The same data should NOT be saved in different tables.
-
-
extend:
-
split the text: long text can be stocked individually, like an extra k-v database
-
split the history: seperate the current data and historical data
-
add the index: index helps search.
-
DO NOT use JOIN: never search 2 or more table at one time
-
LDAP user
-
install
django-python3-ldap
-
config setting.py
-
run
python .manage.py ldap_sync_users
import csv
Django can create commands. We use custom command to import csv.
-
put csv on the server
-
create file in folder:
management/commands
-
create command: import_candidates.py
-
run command
python manage.py import_candidates --path /path/to/your/file.csv
Export csv
We can add export csv action to admin page.
-
create export csv function
The function reads data from database, and returns a http response with
content_type='text/csv'
-
add the function into
actions
inModelAdmin
Logs
We can config logs in setting.py
-
formatters: config format of logs
-
handlers: how to log
-
logger: use handlers to write logs (root is a special logger)
We can make custom logger, too.
import logging
logger = logging.getLogger(__name__)
logger.info('my log')
env settings
We can create different env for different modes (dev, test, prod, etc)
-
create python package (a folder with
__init.py
), namedsettings
-
create
base.py
as base settings, and point to it# manage.py import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.base')
-
create
local.py
,production.py
, which importsbase.py
# production.py from .base import * DEBUG = False ALLOWED_HOSTS = ["127.0.0.1"]
put
local.py
in.gitignore
-
run server:
python manage.py runserver --settings=settings.local