Skip to content

Instantly share code, notes, and snippets.

View harunurkst's full-sized avatar

Harun Ur Rashid harunurkst

View GitHub Profile
@harunurkst
harunurkst / datatable_with_django.js
Created February 9, 2020 06:10
Use JQuery datatable with Django Rest Framework
$(document).ready(function(){
$('#search-data').dataTable( {
destroy: true, // destroy previous datatable to remove error.
"ajax": url,
"columns": [
{"data":"latitude"},
{"data":"longitude"},
{"data":"data__product_data__Name"},
{"data":"id__count"},
]
@harunurkst
harunurkst / object_count_per_month.py
Last active November 10, 2020 04:47
Count number of object created or total number of amount per month in Django
class FundRaisePerMonth(APIView):
def get(self, request):
year = datetime.date.today().year
# Filter data as monthly(number serial) [{'month_serial': views_count} like [{'1': 50, '2': 55}]
queryset = CustomUser.objects.filter(date_joined__year=year)
search = queryset.annotate(month=ExtractMonth('date_joined'),).order_by('month').values('month')\
.annotate(total=Sum('amount')).values('month', 'total')
# convert int month to str month, 1 to January
data = []
$.ajax({
url: apiUrl,
method: 'POST',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(orderData),
headers: {
'X-CSRFToken': csrftoken,
'Accept': 'application/json',
'Content-Type': 'application/json'
#!/bin/bash
# Initialize credential veriable
dbname=teamshape
dbuser=admin
userpass=admin
# install python3.8
echo "Installing python3.8"
sudo add-apt-repository ppa:deadsnakes/ppa
with open(str(BASE_DIR) + '/oidc.key', 'rb') as f:
OIDC_RSA_PRIVATE_KEY = f.read().decode()
@harunurkst
harunurkst / aggregate_sum.py
Created July 24, 2023 23:47
Django Aggregate SUM example
deposit_sum = Sum('amount', filter=Q(transaction_type='deposit'))
withdraw_sum = Sum('amount', filter=Q(transaction_type='withdraw'))
deposit = Savings.objects.filter(branch=branch).aggregate(
total_deposit= deposit_sum - withdraw_sum
)['total_deposit']