U10399 – LAST NAME First name
BSc in Information Technology and Automation Systems in Industry (ICT)
Final Project Report
Development of Administrator zone with the help of DJANGO backend tool
I had the chance to investigate and play around with a variety of Django admin panel functions during
my internship. I received practical experience in designing and maintaining database models, setting
up custom fields, and establishing connections between various models. The admin interface's CRUD
(Create, Read, Update, Delete) activities on database entries can now be carried out with ease thanks
to the models I learnt how to register there.
1|P a g e
U10399 – LAST NAME First name
BSc in Information Technology and Automation Systems in Industry (ICT)
Final Project Report
Standard admins zone in Django project
Activating the application.
In order to keep track of the application and be able to create new database tables for its models, we
had to activate it.
Creating-applying migrations.
Now that there is a data model for the blog posts, we needed a database table for it. Django always
comes with a migration system that tracks the changes made to models and enables them to
propagate into the database. As mentioned, the migrate command applies migrations for all
applications listed in INSTALLED_APPS; it synchronizes the database with the current models and
existing migrations. First, we will need to create an initial migration for the Post model.
Django administration site.
Now we started the development server with the python manage.py runserver command and open
http://127.0.0.1:8000/admin/ in our browser.
When we registered a model in the Django administration site, we could get a user-friendly Interface
generated by introspecting of the models that allows us to list, edit, create, and delete objects in a
simple way.
Django uses different form widgets for each type of field. Even complex fields, such as the
DateTimeField, are displayed with an easy interface, such as a JavaScript date picker. We had to fill in
the form and click on the SAVE button.
We can see that the fields displayed on the post list page are the ones we specified in the list_display
attribute. The list page included a right sidebar that allows us to filter the results by the fields included
in the list_filter attribute. A search bar has appeared on the page. This was because we have defined
a list of searchable fields using the search_fields attribute. Just below the search bar, there are
navigation links to navigate through a date hierarchy; this has been defined by the date_hierarchy
attribute. We can also see that the posts could be ordered by STATUS and PUBLISH columns by default.
We have specified the default sorting criteria using the ordering attribute.
Next, click on the ADD POST link. We also noted some changes here. As we type the title of a new
post, the slug field was filled in automatically. We have told Django to prepopulate the slug field with
the input of the title field using he pre populated_fields attribute. Also, the author field was displayed
with a lookup widget that can scale much better than a drop-down select input when we have
thousands of users.
Working with QuerySets and managers. Now that we had a fully functional administration site to
manage our blog's content, it's time to explore how to retrieve information from the database and
interact with it.
Making innovative objects. We must open the terminal and run the following command to open the
Python shell: python manage.py shell
2|P a g e
U10399 – LAST NAME First name
BSc in Information Technology and Automation Systems in Industry (ICT)
Final Project Report
We already knew how to retrieve a single object from the database using the get() method. We
accessed this method using Post.objects.get(). Each Django model has at least one manager, and the
default manager is called objects. We got a QuerySet object using the model manager.
Delete/remove objects.
Extra details including views
Listing and concerning detail views
We start by creating a view to display the list of posts. Edit the views.py
file of our blog application and make it look like this:
from django.shortcuts import render,
get_object_or_404 from .models import Post
def
post_list(re
quest):
posts = Post.published.all()
return render(request,'blog/post/list.html', {'posts':
posts})
We just created our first Django view. The post_list view takes the request object as the only
parameter. This parameter is required by all views. In this view, we retrieved all the posts with the
published status using the published manager that we created previously. Finally, we used the
render() shortcut provided by Django to render the list of posts with the given template. This function
takes the request object, the template path, and the context variables to render the given template.
It returns an HttpResponse object with the rendered text (normally HTML code). The render() shortcut
takes the request context into account, so any variable set by the template context processors is
accessible by the given template. Template context processors are just callable that set variables into
the context.
Canonical URLs for models
3|P a g e
U10399 – LAST NAME First name
BSc in Information Technology and Automation Systems in Industry (ICT)
Final Project Report
A canonical URL is the preferred URL for a resource. We had different pages in our site where we
displayed posts, but there is a single URL that we use as the main URL for a blog post. The convention
in Django is to add a get_absolute_url() method to the model that returns the canonical URL for the
object.
When we commenced adding content to a blog, we might easily reach the point where tens or
hundreds of posts are stored in the database. Instead of displaying all the posts on a single page, we
may desire to split the list of posts across several pages. This can be achieved through pagination. We
can define the number of posts we want to display per page and retrieve the posts that correspond
to the page requested by the user. Django has a built-in pagination class that allows us to manage
paginated data easily.
Complex features
Sending posts by use of an email
The First, allowing users to share posts by sending them via email was considerable to reckon.. In
order to allow our users to share posts via email, we needed to do the following steps:
• We created a form for users to fill in their name, their email, the email recipient, and optional
comments
• We created a view in the views.py file that handles the posted data and sends the email
• We added a URL pattern for the new view in the urls.py file of the blog application
• We created a template to display the form
Let's start by building the form to share posts. Django has a built-in forms framework that allows us
to create forms in an easy manner. The forms framework makes it simple to define the fields of our
form, specify how they have to be displayed, and indicate how they have to validate input data. The
Django forms framework offers a flexible way to render forms and handle data.
We built a comment system wherein users will be able to comment on posts. To build the comment
system, we were to do the ordinary following steps:
1. Creating a model to save comments
2. Creating a form to submit comments and validate the input data
3. Adding a view that processes the form and saves a new comment to the database
4|P a g e
U10399 – LAST NAME First name
BSc in Information Technology and Automation Systems in Industry (ICT)
Final Project Report
4. Editing the post detail template to display the list of comments and the form to add a new
comment
This is my Comment model. It contains a ForeignKey to associate a comment with a single post. This
many-to-one relationship is defined in the Comment model because each comment was made on one
post, and each post may have multiple comments. The related_name attribute allows us to name the
attribute that we use for the relationship from the related object back to this one. After defining this,
we can retrieve the post of a comment object using comment.post and retrieve all comments of a
post using post.comments.all(). If we don't define the related_name attribute, Django uses the
name of the model in lowercase, followed by _set (that is, comment_set) to name the relationship of
the related object to the object of the model, where this relationship has been defined. We have
included an active Boolean field that we will use to manually deactivate inappropriate comments. We
are to use the created field to sort comments in a chronological order by default. The new Comment
model that we just created is not yet synchronized into the database.
In conclusion
My responsibility in the practise, namely Kelajak academy, was as to coding the back-end of the project
partly as I was assigned to do other tasks whereas my colleagues I worked with were responsible for
other parts. In addition to this, I learnt how to deal with certain issues by finding a simple and complex
solutions. Apart from that, I became easy-going, meaning that I am able to work with other partners
and potential clients in other projects. Hopefully, the act of doing so can result in huge progress in the
future.
5|P a g e