In order to interact with Slack, we need to quickly build some business logic. Luckily, that is super easy with Django. We will generate some entities using Django models, and provide an admin interface so that we can create & modify them. One of the reasons I've chosen Django for this tutorial is that we can do this without building a custom UIs.
Our application will allow users to log in and report hours on their projects. They'll also be able to see other user's reports. Simple as that.
We will:
- Create
Projectmodel that will hold information about a project ProjectReportmodel that will be used to report hours for each project
Create reports models
-
pipenv run ./manage.py startapp projects -
Add
projectsstring toINSTALLED_APPSin yoursettings.py -
Create
ProjectandProjectReportmodel
projects/models.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22from django.contrib.auth import get_user_model from django.db import models User = get_user_model() class Project(models.Model): name = models.CharField(max_length=255) logo = models.ImageField(null=True, blank=True) def __str__(self): return self.name class ProjectReport(models.Model): project = models.ForeignKey(Project, on_delete=models.CASCADE) description = models.TextField() hours = models.FloatField() # if we delete a user we don't want to loose the reported hours user = models.ForeignKey(User, on_delete=models.PROTECT) def __str__(self): return f"{self.project.name} - {self.hours} hours - {self.user.username}"
and add them to admin interface
projects/admin.py
from django.contrib import admin
from .models import Project, ProjectReport
admin.site.register(Project)
admin.site.register(ProjectReport)
pipenv install Pillow
We need to do this, because we've added an ImageField..
pipenv run ./manage.py makemigrations&&pipenv run ./manage.py migrate
git push deploy master from Heroku.
🎉 You can now check our models in the admin interface.



