Skip to content

Instantly share code, notes, and snippets.

View mmkhitaryan's full-sized avatar

Marat Mkhitaryan mmkhitaryan

View GitHub Profile
@kissgyorgy
kissgyorgy / sqlalchemy_conftest.py
Last active November 19, 2024 23:52
Python: py.test fixture for SQLAlchemy test in a transaction, create tables only once!
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from myapp.models import BaseModel
import pytest
@pytest.fixture(scope="session")
def engine():
return create_engine("postgresql://localhost/test_database")
@dhbradshaw
dhbradshaw / gist:e2bdeb502b0d0d2acced
Last active August 16, 2023 17:50
Rename field using migrations in django 1.7
To change a field name in django 1.7+
1. Edit the field name in the model (but remember the old field name: you need it for step 3!)
2. Create an empty migration
$ python manage.py makemigrations --empty myApp
3. Edit the empty migration (it's in the migrations folder in your app folder, and will be the most recent migration) by adding
migrations.RenameField('MyModel', 'old_field_name', 'new_field_name'),
to the operations list.
@sweetports
sweetports / phpstorm-FTPerror(timestamp)
Last active March 3, 2021 08:18
Phpstorm FTP uploading error(timestamp)
PhpstormでFTPアップロードで以下のエラーが出るとき
Failed to change timestamp of the file
Tool - Deployment -Optionsにて、「Preserve files timestamps」のチェックを外す
@iambibhas
iambibhas / django-image-save.py
Created February 27, 2013 21:30
Programatically save ImageField in Django
import requests
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
def save_image_from_url(model, url):
r = requests.get(url)
img_temp = NamedTemporaryFile(delete=True)
@dustinfarris
dustinfarris / session_enabled_test_case.py
Last active April 18, 2024 22:17
Setting session variables whilst testing with Django's TestCase
"""
Attempting to set session variables directly from TestCases can
be error prone. Use this super-class to enable session modifications
from within your tests.
Usage
-----
class MyTest(SessionEnabledTestCase):