Free CRM Part 1: Idea
Salesforce is expensive. Lets make our own CRM (Customer Relationship Management) software.
Open up a terminal window and install django with pip.
pip install django
Create a new Django Project called 'mycrm' or whatever you like. Change directory.
django-admin startproject mycrm
cd mycrm
Create a new Django app. I like to call it something slightly different to not get confused.
python manage.py startapp crm
Now the project directory looks like this.
Now we need to open the file mycrm/mycrm/settings.py and add our app 'crm'.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crm',
]
OK now we are ready to go. Lets step away from the keyboard and think about what our users would like from CRM software. I'm thinking about the basics.
This is the kind of information kept on clients. We will start with this and add more later.
Open mycrm/crm/models.py and paste code.
from django.db import models
class Customer(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=20, blank=True)
address = models.TextField(blank=True)
def __str__(self):
return self.name
Now it's time to create and apply migrations.
python manage.py makemigrations crm
python manage.py migrate
Once migrations are applied, we continue with administration.
Open crm/admin.py and paste the following.
from django.contrib import admin
from .models import Customer
@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
list_display = ('name', 'email', 'phone')
search_fields = ('name', 'email')
Now I love Flask but here we have more of a batteries included, blueprint system. We import the Customer model we created and create a new class CustomerAdmin().
Next we create a super user.
python manage.py createsuperuser
This will prompt for a username, email, and password (twice). Fill that out on your own and write down the data!
Next it's time to create our beautiful views. Open crm/views.py.
领英推荐
# crm/views.py
from django.shortcuts import render
from .models import Customer
def customer_list(request):
customers = Customer.objects.all()
return render(request, 'crm/customer_list.html', {'customers': customers})
Open crm/urls.py and setup a url pattern. We need to create another urls.py file inside crm.
from django.urls import path
from .views import customer_list
urlpatterns = [
path('', customer_list, name='customer_list'),
]
And a second file mycrm/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('crm.urls')),
]
Now we can work on the front-end. Create a templates directory like so.
mkdir -p crm/templates/crm
This can be confusing so here is how I did it.
Create a new file in this directory base.html and paste our front-end code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CRM</title>
<link rel="stylesheet" >
</head>
<body>
<section class="section">
<div class="container">
{% block content %}
{% endblock %}
</div>
</section>
</body>
</html>
And next a customer list template for our precious CRM data. Create a file customer_list.html.
<!-- crm/templates/crm/customer_list.html -->
{% extends "crm/base.html" %}
{% block content %}
<h1 class="title">Customer List</h1>
<table class="table is-fullwidth">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
</tr>
</thead>
<tbody>
{% for customer in customers %}
<tr>
<td>{{ customer.name }}</td>
<td>{{ customer.email }}</td>
<td>{{ customer.phone }}</td>
<td>{{ customer.address }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
It's ready, phew. A lot of separate files and modifications. Django is a quality framework.
Lets start up our CRM and see what happens.
(.venv) bot@botnet:~/PycharmProjects/CRM/mycrm$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
June 11, 2024 - 22:27:57
Django version 5.0.6, using settings 'mycrm.settings'
Starting development server at https://127.0.0.1:8000/
Quit the server with CONTROL-C.
Now our little CRM is running over at https://127.0.0.1:8000
The site looks good. I like the font, lets head to https://127.0.0.1:8000/admin and login with that username we created in terminal earlier.
There is an area to add a new customer, I encourage you to explore this.
Once I save the data, I can see the new data back at our main page.
So there is a lot I can do here. This is just a basic implementation. I hope to continue this project. CRM software is expensive so it would be nice to create a FREE version of this software. Something that can be securely hosted locally or on a cloud platform.
Bye -Henry