sort and filter by objectid in mongo via python(pymongo)
for example, query collection that the ‘_id’ greater then the given objectid, and get the top 10 latest ones id = ObjectId('50b41c5670b35f4581f6df4f')sourceList = yourDB.Post.find({'_id':{'$gt':...
View Articleconvert string to datetime in python
from datetime import datetime date_object = datetime.strptime(‘Jun 1 2012 1:33PM’, ‘%b %d %Y %I:%M%p’) notes, the ‘format’ of the datetime string must match the string need to converted to datetime.
View ArticleImplementing a 404 Template in django
Implementing a 404 Template If DEBUG is True, Django displays the useful 404 error page. But if DEBUG is False, then it does something different: it renders a template called 404.html in your root...
View Articledatetime format in python
# Convert string to datetime from datetime import datetime date_object = datetime.strptime('Jun 1 2013 1:33PM', '%b %d %Y %I:%M%p') date_object = datetime.strptime('2013-2-5', '%Y-%m-%d') # You can use...
View Articledjango, export csv file
in html form <form action=” method="POST"> <input type="text" id=’txtName’ name="txtName" value=txtName> <button value="submit">Submit</button>...
View ArticleJSON encoder and decoder
>>> import json>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])'["foo", {"bar": ["baz", null, 1.0, 2]}]'>>> print json.dumps("\"foo\bar")"\"foo\bar">>> print...
View Articledefine models class in django
__author__ = ‘Administrator’ from django.db import models from django.contrib import admin class AvaliabeSites(models.Model): name = models.CharField(max_length=200) code =...
View ArticleFibonacci series up to n in Python
>>> def fib(n): … a, b = 0, 1 … while b < n: … print b, … a, b = b, a+b … >>> fib(50) 1 1 2 3 5 8 13 21 34
View Article