Create a task manager in python
In this tutorial, we'll first build a simple to-do app in Django using Python. Then we'll explore some ways we can visualize the resulting data in our database client. Want to build an analytics dashboard or twitter scraper instead? Check out these previous tutorials. Show
Build an Analytics Dashboard with Django and Arctype Django’s versatility makes it the ideal framework for developers endeavoring to collect website analytics, which can then be visualized and analyzed using Arctype’s dashboard functionality—truly a perfect synergy. Arctype BlogOchuko Onojakpor Build Twitter Heat Maps with Tweepy, Django and Arctype Have you ever wanted to track your tweet activity on Twitter? Then this article is for you. I love how Django’s ORM makes it easy to model a database and modify it with views (i.e., the app’s functional back-end). Arctype BlogOchuko Onojakpor PrerequisitesTo fully understand this tutorial, you will need the following:
Python setupInstalling PythonFirst, let's install Python using this link. Then, we can select our OS and download
it. This tutorial was built on Windows. We can run the command Creating a virtual environmentLet's create an isolated virtual environment for this project. Virtual environments help us avoid installing dependencies globally on our system. This helps to make sure that the dependencies of other projects won't be included within the dependencies of our current project, even though they're all on the same local machine. To do that run the following command. Creating a virtual environment.Next, activate the virtual environment by navigating to the base directory of our new virtual environment (in our example, it has the name "env"). Then, navigate into the Scripts folder and run the executable file "activate." Django SetupYou can install Django Web Framework with pip and then follow these steps. Create a projectNow, let's create the project. We can do this by running the command Creating the projectHere, we can name the project however we like, but be sure to be descriptive. Create an appLet's navigate to the The app is created successfully. We can now open the project in our favorite IDE. MigrationsIn Django, we use migrations to move changes we make to our models (adding a field, deleting a model, etc.) into our database schema. First, we need to make migrations to our database. Run the command Makemigrations running.Now let's run our app to see if we have successfully installed and our project properly set up. To do this, we are to change the directory into our project and run the command
We have started our development server at http://127.0.01:8000/! So we can now open our browser to access our app using this URL. If everything works fine, the screen with the same image below is displayed as the default Django page. The landing page of a default project.Now we want to make some configurations inside the Editing Settings.py to add MySQL to DjangoIn your Connecting to the SQL server.Todo list app data modelNext, we want to create a model. This model will determine how the task will be stored on the database. The task will have seven properties, a Note:
our Now let's go ahead and make migrations. Any time changes are made to our models, we need to make migrations. Once that is completed, we will find a new file inside the migrations folder as shown below. Performing the migrations.We didn't write this code manually. This is the SQL code that Django has handled for us. Next, we migrate with python manage.py migrate. Migrate is responsible for applying and reapplying migrations. Running the migrations.Now we test that the CRUD operation was successful by registering the task on the admin panel as follows: Registering to confirm the CRUD operation succeeded.
...as it appears in the IDE.Task management APITo build the API we will install and use the Django REST Framework. Creating a superuser and adding the rest_frameworkLet's create a superuser with the following command: Next, we'll need to add the Django rest_framework to the list of apps Creating the serializersJSON stands for JavaScript Object Notation. Serializers convert the model class to JSON so that the frontend can work with the received data. Serializing the model class to JSON....and as it appears in the IDECreating the viewThe view is simply a Python function that takes an HTTP request and returns a response. This response may be the HTML contents, for example. The view itself houses the business logic that is necessary to return a response to a client that makes an HTTP call to it. Creating the TaskView...and as it appears in the IDE.The URLThe URL is used to map path expressions to Python functions (your views). It first receives HTTP requests and routes them to the right matching function in views.py to handle the request. Now let's go to the URL that is in the project folder and add the following code: Managing the URL patterns and routes.The code above as it appears in the editor.Accessing our endpointsTo access our endpoint run your app and visit http://127.0.0.1:8000/api/tasks/ and add a task. Adding a task to our list.Boom! We have it on our task manager. We can get a particular task by appending the This section has taught us how to build a task management app that performs CRUD operations. Now, we will use a SQL client to visualize the data on our database. Visualize and query task dataNext, we select the SQL type we are most familiar with. In the course of this article, we would be connecting to a MySQL relational database. Connecting to the database in Arctype.Visualizing tablesI made a sample data .csv for this tutorial. First, I created a Google sheet, exported it to a .csv, and then imported it. This data table contains columns: Creating a dashboard to group together activitiesNow, we
are going to display our list of activities. First, we'll write an SQL query that will display our data set. Click on the We can start by renaming our query and save it in the editor's heading: Retrieving the data we're interested in.The result we get should look like the screenshot below: Setting up the dashboard in Arctype.Next, we can now click on the Next, click on "Add tab" and select Then, click on the select chart data and select Change the title of the dashboard component and select Next, we create a table component to display the activities that were most productive. Create
a new query called The activities_complete queryThe query, as seen in
ArctypeThen, click on the Lastly, we click on the select chart data button and select the Creating a pie chartHere, we are going to create chart components with Arctype to display our datasets in pie charts. We start the process by using our previous query command. Then, simply select the chart type and change it to Mixing different types of charts in one dashboardHere, we are going to create chart components with Arctype to display our datasets in bar charts. We repeat the same process as we did with pie charts. We change the chart type to ConclusionThis article was divided into two sections. First, we learned how to use a Python framework (Django) to create a task management system. Secondly, we explored the data model of our task management app using a SQL client. While we did that, Arctype to visualize our tables and columns using queries and dashboards. We also learned how to showcase our dataset into pie charts, bar charts, area charts, and line charts. JOIN the Arctype Newsletter Programming stories, tutorials, and database tips every 2 weeks |