This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> Airport.objects.filter( | |
iata_code='DME', | |
).values_list( | |
'iata_code', | |
'city__name', | |
'city__country__name', | |
) | |
[(u'DME', u'Moscow', u'Russia')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Project(models.Model): | |
name = models.CharField(max_length=140) | |
parent = models.ForeignKey('self', blank=True, null=True) | |
class ProjectForm(ModelForm): | |
def __init__(self, *args, **kwargs): | |
super(ProjectForm, self).__init__(*args, **kwargs) | |
ordered = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
duration = datetime.timedelta(seconds=1823723) # 21 days, 2:35:23 | |
days, seconds = duration.days, duration.seconds # (21, 9323) | |
hours = seconds // 3600 # 2 | |
minutes = (seconds % 3600) // 60 # 35 | |
seconds = (seconds % 60) # 23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SOCIAL_AUTH_FACEBOOK_SCOPE = [ | |
'email', | |
'user_friends', | |
'friends_location', | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export CPPFLAGS=-Qunused-arguments | |
export CFLAGS=-Qunused-arguments | |
brew install libjpeg | |
#pip install Pillow | |
#pip install pyOpenSSL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
name = Vera | |
email = vera@example.com | |
[color] | |
ui = true | |
[alias] | |
st = status | |
ci = commit | |
last = log -1 HEAD | |
co = checkout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -name "*.pyc" -exec rm '{}' ';' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export CFLAGS=-Qunused-arguments | |
export CPPFLAGS=-Qunused-arguments | |
pip install lxml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post(models.Model): | |
image = models.ImageField( | |
max_length=255, | |
upload_to='uploads/blog', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_queryset(self): | |
queryset = super(MyModel, self).get_queryset() | |
states_filter = [ | |
item.strip() | |
for item in config.STATES.split(',') | |
] | |
if not states_filter: | |
MyModel.objects.none() | |
q = Q() | |
for state in states_filter: |
OlderNewer