Skip to content

Instantly share code, notes, and snippets.

@bencleary
Last active April 22, 2018 18:22
Show Gist options
  • Save bencleary/f6ba3f78d74d735b92d31357086498dd to your computer and use it in GitHub Desktop.
Save bencleary/f6ba3f78d74d735b92d31357086498dd to your computer and use it in GitHub Desktop.
from django.contrib import admin
from .models import *
class CustomerAdmin(admin.ModelAdmin):
list_display = ['first_name', 'last_name', 'email', 'welcome_email_sent']
list_display_links = ['first_name', 'last_name']
admin.site.register(Customer, CustomerAdmin)
from django.apps import AppConfig
class CrmAppConfig(AppConfig):
name = 'crm_app'
def ready(self):
import crm_app.signals
default_app_config = 'crm_app.apps.CrmAppConfig'
from django.db import models
class Customer(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField(max_length=255)
welcome_email_sent = models.DateTimeField(blank=True, null=True)
created_at = models.DateTimeField(auto_now=True)
def full_name(self):
return f'{self.first_name} {self.last_name}'
class Meta:
db_table = "myawesomeapp_crm_customer"
verbose_name = "Customer"
verbose_name_plural = "Customers"
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import *
@receiver(post_save, sender=Customer)
def send_welcome_email(sender, instance, created, *args, **kwargs):
if created:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment