Introduction:
Script use to get the pincode from a address. I used regulatr expression to find it. At first, we will check check pincode end of address. If we didn't get, then check between address. Here I assumed pincode starts with 7 and len should be 6 (ex 700002)
Script:
def getPin(myStr):
pin=re.search(r"7(\d{0,5})$",myStr)# check for pincode end of string
if not pin:
pin=re.search(r"7(\d{0,5})[ ]",myStr) # check for pincode in between string
if pin:
return pin.group().strip()
else:
return ''
Labels: Python
Sometimes, we required to change the order of field rendering in modelform. We can override by adding "keyorder" in __init__ method.
class MyModel(ModelForm):
def __init__(self, *args, **kwargs):
super(MyModel, self).__init__(*args, **kwargs)
self.fields.keyOrder = ['Field1', 'Field2','Field3', 'Field4']
Labels: Django, Django-Modelform, Python
Python Generate random lowercase string which does not contain o,0, i, 1
0 comments Posted by jayapal at 10:46 PM
def code_generator(size=6):
chars = "abcdefghjklmnpqrstuvwxyz23456789"
return ''.join(random.choice(chars) for x in range(size))
How to check JQuery element exist using terinary operation
$('.mydiv').length ? $('.mydiv').remove(): 0; // remove element, if already rendered
Labels: Django, JavaScript, JQuery
Git Create New Repo
create a repository in github, say odeskcreate a work folder in ur localmachine. Say odeskcd odeskgit initcreate some sample filesgit add . (add the new files in git)git commit -m “initial commit”git remote add origin https://xxxxx@github.com/xxxx/odesk.gitgit push origin mastermodify the filegit addgit status -sgit commit -a -s “updateed the file”git push origin master
Git Branch
git branchgit checkout(make branch as active) git checkout -bdo the modify in the files and add git addgit commit -a -m “my commit message”git push origin
Git Merge
git checkout mastergit merge hotfixgit push origin master
Cmd |
|
|
git –version | identify the version | |
git |
Help | |
git config --global user.name " |
config user name | |
git config --global user.email " |
config email | |
git config --global core.editor ' |
config editor | |
cat ~/.gitconfig | ||
git init | To initialize a Git repository from an existing directory, | |
git add . | add files | |
git commit -m ' |
commit the changes along with message. | |
git log | list all the commits | |
git clone git://github.com/schacon/munger.git | clone(push) the git repo | |
git commit -a | editor will oen for enter the commit message | |
git remote add origin https://xxxxx@github.com/xxxxx/odesk.git | To connect your local repository to your GitHub account, you will need to set a remote for your repo and push your commits to it: | |
git push origin master | push the commit to the repo | |
git branch mybranch | create a new branch | |
git checkout mybranch | make mybranch as active | |
git checkout -b mybranch | Creates a new branch called "mybranch" and makes it the active branch | |
git checkout |
switch between branch | |
git merge |
To merge active branch with |
|
git branch -d |
to delete branch | |
git push origin --delete |
To delete remote branch i.e. from GitHub |
Introduction:
This section will teach you to How to create not equal queryset filtering.
Method:
This section will teach you to How to create not equal queryset filtering.
Method:
from django.db.models import Q
Models.objects.exclude(MyField='foo')
Models.objects.filter(~Q(MyField='foo'))
Introduction:
This section will teach you to How to create complex query/filter using django Q objects.
Method:
from django.db.models import Q
q_object = Q()
q_object.add(Q(MyField__icontains='foo'), Q.OR) # OR'ing
q_object.add(Q(MyField__icontains='foo'), Q.AND) # AND'ing
q_object.add(Q(**{'MyField': 'foo'}), Q.AND) # QueryDict
Subscribe to:
Posts (Atom)