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: |
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
$('body').on('click', '.autocomplete-light-widget .deck .remove', function() { | |
// do something | |
}); |
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 swap(a, i, j): | |
t = a[i] | |
a[i] = a[j] | |
a[j] = t | |
def permutations(a, i, n): | |
if i == n: | |
print a | |
else: | |
for j in range(i, n): |
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 | |
import calendar | |
def get_days_passed(before, after): | |
d1 = before.date() | |
d2 = after.date() | |
return abs(d1 - d2).days | |
d1 = datetime.datetime(2014, 05, 24, 17, 0, 0) | |
d2 = datetime.datetime(2014, 05, 24, 18, 5, 0) |
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
# generate a new key | |
ssh-keygen -t rsa -b 4096 -f ~/.ssh/my_key | |
# private key | |
cat ~/.ssh/my_key | |
# public key | |
cat ~/.ssh/my_key.pub | |
# add key | |
ssh-add ~/.ssh/my_key |
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
.item-blur { | |
/* blur */ | |
filter: blur(5px); | |
-webkit-filter: blur(5px); | |
-moz-filter: blur(5px); | |
-o-filter: blur(5px); | |
-ms-filter: blur(5px); | |
filter: url(data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+DQoJPGZpbHRlciBpZD0iYmx1ciI+DQoJCTxmZUdhdXNzaWFuQmx1ciBzdGREZXZpYXRpb249IjMiIC8+DQoJPC9maWx0ZXI+DQo8L3N2Zz4=#blur); | |
-webkit-transition: -webkit-filter .50s; | |
/* prevent copy */ |
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 ContactForm(forms.ModelForm): | |
def __init__(self, *args, **kwargs): | |
super(ContactForm, self).__init__(*args, **kwargs) | |
self.fields['topic'].queryset = ContactTopic.objects.filter( | |
is_active=True, | |
) | |
class Meta: | |
model = ContactMessage |
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.forms.models import model_to_dict | |
instance = MyModel.objects.first() | |
fields = model_to_dict(instance).keys() |
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 BasicAdmin(admin.ModelAdmin): | |
# ... | |
def get_urls(self): | |
urls = super(BasicAdmin, self).get_urls() | |
my_urls = patterns( | |
'', | |
(r'^download_as_xls/$', self.download_as_xls_view) | |
) | |
return my_urls + urls |