Skip to content

Instantly share code, notes, and snippets.

View ebsaral's full-sized avatar

Emin Buğra Saral ebsaral

View GitHub Profile
@ebsaral
ebsaral / replace_duplicates.py
Last active August 8, 2017 14:33
Replace duplicate objects with the original
from django.db import transaction
from django.db.models.deletion import Collector
from django.db.models.fields.related import ForeignKey, ManyToManyField, OneToOneField
duplicates = []
items = {}
client = Client.objects.get(name='Demo')
for c in Company.objects.filter(active=True, client=client):
company_name = c.name
@ebsaral
ebsaral / example_hfexcel_template.json
Created May 26, 2019 17:12
Example HFExcel JSON Template
{
"sheets": [
{
"key": "sheet1",
"name": "Example Sheet 1",
"columns": [
{
"name": "Column 1",
"width": 2,
"args": [
@ebsaral
ebsaral / error.js
Created October 27, 2020 13:43
JS Simple error
throw new Error('ERROR!');
@ebsaral
ebsaral / ex_migration_script.py
Created July 12, 2017 12:29
Converting a model to multi-table inheritance in Django - Migration Script
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class CopyFieldsBetweenTables(migrations.operations.base.Operation):
reversible = False
def __init__(self, model_from_name, model_to_name, columns):