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
-- Get Max ID from table | |
SELECT MAX(id) FROM table; | |
-- Get Next ID from table | |
SELECT nextval('table_id_seq'); | |
-- Set Next ID Value to MAX ID | |
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table)); |
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
#put in lib/tasks/fixtures.rake | |
namespace :db do | |
namespace :fixtures do | |
desc 'Create YAML test fixtures from data in an existing database. | |
Defaults to development database. Set RAILS_ENV to override.' | |
task :dump => :environment do | |
sql = "SELECT * FROM %s" | |
skip_tables = ["schema_migrations"] | |
ActiveRecord::Base.establish_connection(:development) | |
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name| |
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
# Add your own tasks in files placed in lib/tasks ending in .rake, | |
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | |
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | |
require 'rake' | |
require 'rake/testtask' | |
require 'rake/rdoctask' | |
require 'tasks/rails' |
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
#!/bin/bash | |
set -e | |
# You must place all uncompressed bulk files in the same directory and set | |
# environment variable BULK_DIR, BULK_DB_HOST, BULK_DB_USER, BULK_DB_PASSWORD | |
# NOTES: | |
# 1. If you have your postgresql instance on a docker service, you need to mount | |
# the directory where the bulk files are, otherwise you will get this error: | |
# ERROR: could not open file No such file or directory | |
# 2. You may need to grant execute permissions to this file |
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
from django.contrib.admin import ModelAdmin, register, SimpleListFilter | |
from django.db.models.functions import Length, StrIndex, Substr, NullIf, Coalesce | |
from django.db.models import Value as V | |
from .models import Item | |
class AlphanumericSignatureFilter(SimpleListFilter): | |
title = 'Signature (alphanumeric)' | |
parameter_name = 'signature_alphanumeric' |
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 ExtractInteger(Func): | |
"""Returns the first int value from the string. Note that this | |
requires the string to have an integer value inside. | |
Example of usage: | |
YourModel.objects.filter(something=True).annotate(integer_value=ExtractInteger("field_name")).order_by("-integer_value") | |
""" | |
function = "REGEXP_MATCH" |
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
us_state_names = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", | |
"Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", | |
"Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", | |
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", | |
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", | |
"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", | |
"West Virginia", "Wisconsin", "Wyoming"] |
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
import copy | |
from factory import RelatedFactoryList | |
class RelatedFactoryVariableList(RelatedFactoryList): | |
"""This factory allows you to specify how many related objects do you | |
want to create, but also allows you to define the data for each related | |
object. | |
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
{% load i18n %} | |
{% load admin_urls %} | |
{% load getattribute from pghistory %} | |
<table id="change-history" class="table table-bordered table-striped"> | |
<thead> | |
<tr> | |
<th scope="col">{% trans 'PGH ID' %}</th> | |
{% for column in history_list_display %} | |
<th scope="col">{% trans column %}</th> |
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 OpsIPInfoAdmin(admin.ModelAdmin): | |
def get_readonly_fields(self, request, obj=None): | |
# make all fields readonly | |
readonly_fields = list( | |
set([field.name for field in self.opts.local_fields] + | |
[field.name for field in self.opts.local_many_to_many]))) | |
if 'is_submitted' in readonly_fields: | |
readonly_fields.remove('is_submitted') |
NewerOlder