This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To add a name to migration files rather than 001_auto_20189084774 | |
python manage.py makemigrations --name DESIRED_NAME appName | |
# e.g. if app name is `site` and you want to name migration, `new_side_bar` | |
python manage.py makemigrations --name new_side_bar site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sometimes you need to determine a model name from an object, before using | |
# First long approach may work in every version of Django? not tested | |
import sys | |
model_obj # let model_obj be the model object ( instance) from some input | |
model_name_str = type(model_obj).__name__ # this is model name as string, but we need the object to do the | |
model_object = getattr(sys.modules[__name__], model_name_str) | |
# now we can use model object normally |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`class Blog(models.Model): | |
#some attributes | |
class Entry(models.Model): | |
blog = models.ForeignKey(Group, related_name='entries') . # this is a ForeignKey relationship, not a OneToOneField | |
#more attributes | |
` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# funny thing Heroku scheduler has no way of running a task monthly easily, one has to use a command like this: | |
if [ "$(date +%d)" = 01 ]; then MY_COMMAND; fi | |
# Run task every monday | |
if [ "$(date +%u)" = 1 ]; then MY_COMMAND; fi | |
# Run task every 24th of the year | |
if [ "$(date +%m)" = 12 ] && [ "$(date +%d)" = 24 ]; then MY_COMMAND; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py tenant_command dumpdata --schema="schema-name" app.personalitytypes > app/fixtures/data.json | |
# 'app' and 'schema-name' to be replaced with necessary variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tenary opeartor | |
foo = test? True: False | |
# python equivalent with if else on same line | |
foo = "True" if test else "False" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git commit --amend -m "New commit message" | |
# then | |
git push --force | |
# it creates a new message and creates a merge of the branch with itself it appears | |
# this works assuming no one else did any push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dynamicSort(property) { | |
var sortOrder = 1; | |
if(property[0] === "-") { | |
sortOrder = -1; | |
property = property.substr(1); | |
} | |
return function (a,b) { | |
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0; | |
return result * sortOrder; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku config:set VAR_TO_BE_UPDATED: var_value --app APPNAME | |
# VAR_TO_BE_UDPATED : var_value is the key value pair of your .env variable | |
# APPNAME is the name of the app you want to update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# say you want to extend the expiration date for subscription service to 14 days, in postgres you can do that by | |
update users set expiration_date = expiration_date + interval '14 days'; # users is the table where expiration is stored | |
# I bet this could work, not tested | |
update users set expiration_date += interval '14 days'; | |
# you could do so much more with interval > http://www.postgresqltutorial.com/postgresql-interval/ |