Skip to content

Instantly share code, notes, and snippets.

@a4amaan
a4amaan / Dockerfile
Last active October 30, 2019 12:59
Docker Setup Files for Django Project
FROM python:3.7-alpine
MAINTAINER London App Developer Ltd.
ENV PYTHONUNBUFFERED 1
# Install dependencies
COPY requirements.txt ./
RUN pip install -r requirements.txt
# Setup directory structure
@a4amaan
a4amaan / DRF-dynamic-fields.py
Created November 26, 2019 09:55 — forked from Kmaschta/DRF-dynamic-fields.py
Django Rest Framework - Dynamic Fields
# How to display only interesting fields for a Django Rest Framework API
# /?fields=field1,field2,field3
from rest_framework import serializers, pagination
class DynamicFieldsModelSerializer(serializers.ModelSerializer):
"""
A ModelSerializer that takes an additional `fields` argument that
controls which fields should be displayed.
sudo mkdir /var/www/www.example.com
sudo nano /etc/apache2/sites-available/www.example.com.conf
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www.example.com
<Directory /var/www/www.example.com>
AllowOverride All
</Directory>
</VirtualHost>
@a4amaan
a4amaan / Apache Virtual Host For Django Based Application
Last active December 23, 2019 10:42
Apache Virtual host for Django To Run Along With PHP
<VirtualHost *:80>
ServerName xyz.example.com
ServerAdmin [email protected]
ErrorLog /var/www/web.example.com/error.log
CustomLog /var/www/web.example.com/access.log combined
Alias /static /var/www/web.example.com/static
<Directory /var/www/web.example.com/static>
Require all granted
</Directory>
<Directory /var/www/web.example.com/example>
@a4amaan
a4amaan / functions.py
Created January 19, 2020 11:42
Django Haversine formula to find the Nearest Locations.
def get_nearest_cities(lat, lng, in_radius):
earth_radius = 6371
cities = Location.objects.filter().annotate(
distance=earth_radius * ACos(Cos(Radians(lat)) * Cos(Radians("latitude")) * Cos(
Radians("longitude") - Radians(lng)) + Sin(Radians(lat)) * Sin(
Radians('latitude')))).filter(distance__lt=in_radius).order_by("distance")
return cities
@a4amaan
a4amaan / api.py
Last active April 6, 2020 16:25
Django API for html datatables
class JSONViewMixin(object):
def json_response(self, data, status=200):
return JSONResponse(self.request, data, status=status)
class DataTableView(JSONViewMixin, View):
def get(self, request, *args, **kwargs):
params = request.GET
sort_col_num = params.get('iSortCol_0', 0)
@a4amaan
a4amaan / test.html.slim
Created February 7, 2020 15:35 — forked from kossoff/test.html.slim
Custom parameters for jQuery Datatables with server-side processing
label
input#test-checkbox type="checkbox"
|Test checkbox
table#test-table
javascript:
$(document).ready(function() {
var table = $("#test-table").dataTable( {
"ajaxSource": '#{test_datatable_path}',
export const CommonMixin = {
data() {
return {
dialog: false,
snackbar: {
show: false,
message: null,
color: null
},
search: "",
requiredRule: [v => !!v || "This Field is required."],
if (this.$refs.accountForm.validate()) {
}
<v-form ref="accountForm">
<v-text-field
v-model="account.father_name"
label="Father Name"
ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;