This file contains hidden or 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
    
  
  
    
  | DATABASES = { | |
| 'default': { | |
| 'ENGINE':'django.db.backends.mysql', | |
| ... | |
| 'OPTIONS': {'charset': 'utf8mb4'}, | |
| } | |
| } | 
  
    
      This file contains hidden or 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 CreditCardForm(ModelForm): | |
| card_number = CreditCardField(placeholder=u'0000 0000 0000 0000', min_length=12, max_length=19) | 
  
    
      This file contains hidden or 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 import forms | |
| from django.forms.widgets import TextInput | |
| from django.utils.translation import ugettext_lazy as _ | |
| class TelephoneInput(TextInput): | |
| # switch input type to type tel so that the numeric keyboard shows on mobile devices | |
| input_type = 'tel' | 
  
    
      This file contains hidden or 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 '*.py' -o -name '*.coffee' -o -name '*.scss' \) | xargs wc -l | 
  
    
      This file contains hidden or 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.views.generic import UpdateView | |
| from forms import MyModelForm | |
| from models import MyModel | |
| class MyUpdateView(UpdateView): | |
| # specify a custom ModelForm | |
| form_class = MyModelForm | 
  
    
      This file contains hidden or 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
    
  
  
    
  | ids = [9, 8, 1, 2, 7, 3] | |
| results = Model.objects.filter(id__in=ids).extra( | |
| select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))}, | |
| order_by=['manual'] | |
| ) | 
  
    
      This file contains hidden or 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
    
  
  
    
  | SELECT id, name | |
| FROM table | |
| WHERE name IN (9, 8, 1, 2, 7, 3) | |
| ORDER BY FIELD(id, 9, 8, 1, 2, 7, 3) | 
  
    
      This file contains hidden or 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 itertools import chain | |
| from operator import attrgetter | |
| # ascending oreder | |
| result_list = sorted( | |
| chain(queryset1, queryset2), | |
| key=attrgetter('date_created')) | |
| # descending order | 
  
    
      This file contains hidden or 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 itertools import chain | |
| result_list = list(chain(queryset1, queryset2)) | 
  
    
      This file contains hidden or 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 httplib2 | |
| from googleapiclient.discovery import build | |
| from googleapiclient.http import HttpError | |
| from oauth2client.client import SignedJwtAssertionCredentials | |
| def get_metrics(): | |
| # load the service account key | |
| # this key is managed here - https://console.developers.google.com/project | 
NewerOlder