Skip to content

Instantly share code, notes, and snippets.

View Sheikh2Imran's full-sized avatar
🎯
Focusing

Md Imran Sheikh Sheikh2Imran

🎯
Focusing
View GitHub Profile
@Sheikh2Imran
Sheikh2Imran / xml_to_json.py
Last active December 15, 2019 14:33
Convert xml object to json
from xml.etree.ElementTree import fromstring
from xmljson import parker
xml_data =
<?xml version="1.0"?>
<COMMAND>
<ID>2341</ID>
<NAME>"testname"</NAME>
<EMAIL>"testemail@gmail.com"</EMAIL>
@Sheikh2Imran
Sheikh2Imran / formatted_date.py
Last active December 15, 2019 14:40
Convert date object into a desired format (Ex- 16-12-2019)
import time
from django.utils import timezone
now_time = timezone.now().timetuple()
formatted_time = time.strftime("%d-%m-%Y %H:%M:%S", now_time)
print(formatted_time) # it will print '15-12-2019 10:49:54'
@Sheikh2Imran
Sheikh2Imran / models.py
Last active December 15, 2019 14:41
How to use BrinIndex in Django model
from django.db import models
from django.contrib.postgres.indexes import BrinIndex
class Account(models.Model):
id = models.AutoField()
username = models.CharField(max_lenght=100)
password = models.CharField(max_lenght=200)
class Meta: