View exception.py
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
# decorator function | |
def exception_handler(func): | |
def wrapper(*args): | |
try: | |
func(*args) | |
except Exception as error: | |
print(error) | |
return wrapper |
View timer.py
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 time | |
def timer(func): | |
def wrapper(*args): | |
start_time = time.perf_counter() | |
func(*args) | |
print(f"The execution time is: {time.perf_counter() - start_time:.2f}s") | |
return wrapper |
View admin.py
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.contrib import admin | |
from app.models import Student | |
class StudentAdmin(admin.ModelAdmin): | |
model = Student | |
fieldsets = [ | |
('Personal Information', {'fields': ['name', 'address', 'date_of_birth']}), | |
('Education', {'fields': ['school_name', 'college_name']}), | |
('Professional Information', {'fields': ['current_job', 'company_name']}) |
View admin.py
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.contrib import admin | |
from app.models import Student | |
class StudentAdmin(admin.ModelAdmin): | |
model = Student | |
fields = (('name', 'address'), 'date_of_birth') | |
admin.site.register(Student, StudentAdmin) |
View admin.py
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.contrib import admin | |
from app.models import Student | |
class StudentAdmin(admin.ModelAdmin): | |
model = Student | |
fields = ('name', 'address', 'date_of_birth') | |
admin.site.register(Student, StudentAdmin) |
View admin.py
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.contrib import admin | |
from project.app.models import Student | |
admin.site.register(Student) |
View models.py
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 Student(models.Model): | |
name = models.CharField(max_length=100) | |
address = models.TextField() | |
date_of_birth = models.DateField() | |
school_name = models.CharField(max_length=100) | |
college_name = models.CharField(max_length=100) | |
notes = models.TextField() |
View admin.py
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 datetime import timedelta | |
from django.contrib import admin | |
from myapp.models import CronTask | |
class CronTaskAdmin(admin.ModelAdmin): | |
list_display = ['name', 'get_ist'] | |
list_filter = ['name'] |
View sendgrid_email.py
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 os | |
from sendgrid import SendGridAPIClient | |
from sendgrid.helpers.mail import Mail | |
message = Mail( | |
from_email="verified_email@gmail.com", | |
to_emails="receiver@gmail.com", | |
subject="test", | |
html_content="<p>hi</hi>" |
View luhn.py
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 luhn_checksum(card_number): | |
def digits_of(n): | |
return [int(d) for d in str(n)] | |
digits = digits_of(card_number) | |
odd_digits = digits[-1::-2] | |
even_digits = digits[-2::-2] | |
checksum = 0 | |
checksum += sum(odd_digits) | |
for d in even_digits: | |
checksum += sum(digits_of(d*2)) |
NewerOlder