Skip to content

Instantly share code, notes, and snippets.

@arulmr
arulmr / mail.py
Last active October 28, 2015 09:13
Django mail settings
# EMAIL Server config
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = '587'
EMAIL_HOST_USER = 'example@gmail.com'
EMAIL_HOST_PASSWORD = 'somepassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'example@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
@arulmr
arulmr / admin.py
Last active December 20, 2015 18:28
Auto Complete in Django Admin
class BlockAdmin(NoLookupsForeignKeyAutocompleteAdmin, admin.ModelAdmin):
related_search_fields = {
'city' : ('name', 'state__name', ),
}
@arulmr
arulmr / admin.py
Last active December 22, 2015 00:18
Django 1.5 - Custom User Models
from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin
class UserProfileAdmin(UserAdmin):
form = UserChangeForm
add_form = UserCreationForm
list_display = ('email', 'mobile', 'is_superuser')
list_filter = ('is_superuser',)
@arulmr
arulmr / activate_timezone.py
Last active May 30, 2020 07:36
Getting user timezone from IP in Django
import pytz
from django.utils import timezone
....
timezone.activate(pytz.timezone(user_time_zone))
@arulmr
arulmr / how-to-copy-aws-rds-to-local.md
Created February 24, 2022 05:26 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored