This file contains hidden or 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.db.models import OuterRef, Subquery | |
unique_users_query = (CouponApplication | |
.objects | |
.all() | |
.filter(coupon=OuterRef('id')) | |
.values('user_id') # group cities by state | |
.order_by() # reset ordering | |
.annotate(cnt=Count('*')) | |
.values('cnt')[:1] # Only have 1 row & 1 value allowed |
This file contains hidden or 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
pg_restore -U fmfb_user -h localhost --password -d fmfb_db < /home/sayone/Downloads/12sep18-dump |
This file contains hidden or 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
sudo -u postgres psql | |
create role db_user with password 'db_pass'; | |
create database db_name with owner db_user; | |
alter role db_user WITH LOGIN; |
This file contains hidden or 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
$(document).ready(function() { | |
$(".expenses").on('keyup change', calculateSum); | |
}); | |
function calculateSum() { | |
var $input = $(this); | |
var $row = $input.closest('tr'); | |
var sum = 0; | |
$row.find(".expenses").each(function() { |
This file contains hidden or 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.core.management import BaseCommand | |
from apps.accounts.admin import UserResource | |
from django.contrib.auth import get_user_model | |
import time | |
class Command(BaseCommand): | |
# Show this when the user types help | |
help = "Export all User data" |
This file contains hidden or 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
create user fmfb_user with password 'sayone'; | |
create database fmfb_db with owner fmfb_user; | |
\c fmfb_db |
This file contains hidden or 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 myapp.models import Entry | |
from django.db.models import Q | |
Entry.objects.filter(~Q(id = 3)) | |
#[<Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, ...] |