Free CRM Part 1: Idea

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.

  1. Name (Represented with character field)
  2. Email (Represented with email field)
  3. Phone (Represented with character field)
  4. Address (Represented with text field)

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

要查看或添加评论,请登录

Henry Meier的更多文章

  • Chess Part 2: Finish The Game

    Chess Part 2: Finish The Game

    Welcome back, today we are working on the Front-End. OK, on to the big boy file.

  • Chess Part 1: Multiplayer

    Chess Part 1: Multiplayer

    It's been quite some time since I was able to write an article. Many of my articles have started to blow up so I…

  • Neural Network in C Part 4: Hidden Layer Analysis

    Neural Network in C Part 4: Hidden Layer Analysis

    I want to look under the hood today. Obviously we can see the input layer and output layer.

  • Neural Network in C Part 3: Assembly VS C

    Neural Network in C Part 3: Assembly VS C

    Our Neural Network is fast but we can make it even faster. We will convert the code to assembly, then race the two side…

    2 条评论
  • Neural Network in C Part 2: C Programming

    Neural Network in C Part 2: C Programming

    In this article, we explore how to build a simple feed forward neural network in C to recognize handwritten digits from…

  • Neural Network in C Part 1: Idea

    Neural Network in C Part 1: Idea

    Welcome, normally I enjoy programming in Python and using the TensorFlow library to create machine learning…

  • Free CRM Part 2: Client Notes, Dark Mode, Adding Customers

    Free CRM Part 2: Client Notes, Dark Mode, Adding Customers

    We have a lot of stuff to add to our free CRM software. Small businesses are counting on us! Small businesses don't…

  • Firmware Engineering Part 3: OLED Display

    Firmware Engineering Part 3: OLED Display

    The temperature/humidity sensor works. Currently, this device communicates with a website and shares data over MQTT.

  • Firmware Engineering Part 2: Data Logging Website

    Firmware Engineering Part 2: Data Logging Website

    Last article, we wrote a simple MicroPython program for the ESP32. This device broadcasts raw temperature and humidity…

  • Firmware Engineering Part 1: MicroPython

    Firmware Engineering Part 1: MicroPython

    I bet you thought Python was just for data science and web applications. MicroPython is a full implementation of the…

    1 条评论

社区洞察

其他会员也浏览了