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
| # Install sendgrid | |
| # pip install sendgrid | |
| import sendgrid | |
| import json | |
| sendgrid_source_api_key = 'KEY' | |
| sendgrid_destination_api_key = 'KEY' | |
| sg_source = sendgrid.SendGridAPIClient(apikey=sendgrid_source_api_key) | |
| sg_destination = sendgrid.SendGridAPIClient(apikey=sendgrid_destination_api_key) |
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 os | |
| def convert_line_endings(file, lineEndFrom='\r\n', lineEndTo='\n'): | |
| with open(file, 'rb') as f: | |
| content = f.read() | |
| content = content.replace(lineEndFrom.encode(), lineEndTo.encode()) | |
| with open(file, 'wb') as f: | |
| f.write(content) | |
| print("Converted:", file) |
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
| def getFizzBuzz(fizz, buzz, start=1, end=100, step=1): | |
| for i in range(start, end+1, step): | |
| say = '' | |
| if i % fizz == 0: | |
| say += 'Fizz' | |
| if i % buzz == 0: | |
| say += 'Buzz' | |
| if say == '': | |
| say = i | |
| print(say) |
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
| def format_timedelta_to_HHMMSS(td): | |
| td_in_seconds = td.total_seconds() | |
| hours, remainder = divmod(td_in_seconds, 3600) | |
| minutes, seconds = divmod(remainder, 60) | |
| hours = int(hours) | |
| minutes = int(minutes) | |
| seconds = int(seconds) | |
| if minutes < 10: | |
| minutes = "0{}".format(minutes) | |
| if seconds < 10: |
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 SampleModelAdmin(admin.ModelAdmin): | |
| def sample_method_you_want_to_display_in_admin_fields(self, obj): | |
| ... | |
| return something | |
| sample_method_you_want_to_display_in_admin_fields.short_description = "Text you want to Show as Label" |
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 .utils import LimitFormset | |
| class LimitedInline(admin.TabularInline): | |
| model = Limited | |
| formset = LimitFormset |
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 pdb | |
| pdb.set_trace() # stop execution and let you enter code on CMD | |
| # TO do multi-line statements in pdb, insert code below while on pdb | |
| !import code; code.interact(local=vars()) |
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 os | |
| import urllib2 | |
| from django.core.files import File | |
| from django.core.files.temp import NamedTemporaryFile | |
| class ModelWithImage(models.Model): | |
| image_file = models.ImageField(upload_to='images') | |
| new_img = ModelWithImage() | |
| img_temp = NamedTemporaryFile() |