Don't wanna be here? Send us removal request.
Text
uwsgi vs gunicorn
gunicorn is probably easier because of its simplicity
uwse uwsgi if you need complex settings
0 notes
Text
how to set default cloud run region
gcloud config set run/region asia-northeast1
0 notes
Text
what to do when migration fails
when migration fails,
comment URLs
comment context_processors
0 notes
Text
multiple DBs
can specify multiple DBs in settings.py
can define which models will be saved in which DB in settings.py 's DATABASE_ROUTERS config
also can specify during save() method
1 note
·
View note
Text
migration errors
https://create-it-myself.com/error-resolve/resolve-the-db-does-not-exist/#toc9
do not call DB models in class methods??
0 notes
Text
custom managers 101
Basic usage:
managers are like helper methods for querysets
PollManager.objects.with_counts() prevents you from having to re-write .annotate(...) everywhere
you need to set objects = PollManager() in the Model class
Advanced Usage:
You can also
add more than 1 manager to a model
override the default .all() method
by adding authors = AuthorManager() in the Model class, and defining get_queryset() in the Manager class, you can call Person.authors.all() to get all People objects where role = "A"
Tips:
you can access the original Model in the Manager class by using self.model
don't use __getattr__ because it /can/ prevent managers from being shallow-copied (see here)
don't touch Model._base_manager or Model._default_manager if you're starting out (see here and here)
Links:
https://docs.djangoproject.com/en/4.2/topics/db/managers/
0 notes
Text
dynamic Q objects
can use the |= operator, or write q_object.add
both OR and AND work
0 notes
Text
TIL you can't specify label=None in your forms
you need to do label = "" instead
0 notes
Text
business logic in forms + services
problem: my code contained business logic in both forms and services.
form: display only valid choices
service: ensure only the valid choices were sent
but given this post, I see that
form: display valid choices and validate user input is valid
service: assume input is valid, and handle data updates
0 notes
Text
pass custom params to form
how the docs does it (albeit this is a formset, not a form)
0 notes
Text
DB design patterns
L0 implementation : directly store value in table
L1 : store enum as a table
L2 : extract "Type" to a table
L3 : use mapping table
L4 : not really sure what this is
1 note
·
View note