Skip to content

Instantly share code, notes, and snippets.

View MattFanto's full-sized avatar

Mattia Fantoni MattFanto

View GitHub Profile
@MattFanto
MattFanto / README.md
Last active November 16, 2023 16:51
Django appenddata

Alternative command to django loaddata when it is necessary to append fixture objects into an existing database. Instead of merging fixture data with your existing models (as it does loaddata) it appends all fixtures object by resetting all pk. M2M relations are managed at the end of the process, mapping the old primary keys with the new primary keys:

Example of test (appending data from Website2 into Website1):

# Website 1
python manage.py dumpdata app1 app2 ... > test_append_data_fixtures_pre.json

# Website 1
python manage.py dumpdata app1 app2 ... > fixture_to_import.json
@MattFanto
MattFanto / settings.py
Last active March 12, 2019 23:40 — forked from gregsadetsky/settings.py
See: http://stackoverflow.com/questions/13705328/ -- I was looking for a way to run Selenium tests for a Django app on a staging server hosted on Heroku using a PostgreSQL database. The DjangoTestSuiteRunner creates and destroys the whole database before/after testing, which would not work on Heroku where databases are added via other means (her…
import dj_database_url
TEST_DATABASES = {
'default': dj_database_url.config(env='TEST_DATABASE_URL')
}
# replace path below to point to HerokuTestSuiteRunner class
TEST_RUNNER = 'python.path.to.test_suite_runner.HerokuTestSuiteRunner'
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MattFanto
MattFanto / group_by_sliding_numpy.py
Last active July 3, 2018 16:20
Group by sliding window in tensorflow
length = int(X.shape[0] / step) - window_size
Xt = np.empty((length, window_size*len(GCLOUD_SENSOR_COLS)))
for i in range(length):
Xt[i] = X[i*step:i*step+window_size].ravel()