A blog website comprises Bootstrap, Django and SQLite.
- Create environment and activate it
- Install django
- Create requirement.txt, .gitignore and .env files
- Install decouple
- Move SECRET_KEY to .env and edit settigs.py
- from decouple import config SECRET_KEY = config('SECRET_KEY')
- Change folder name to src and Start project
- Create an app and edit settings>INSTALLED_APPS
- Migrate
- Create superuser
- Run server and check from browser
- Create model (Category and Post)
- Register the modelsin admin.py
- Install pillow and edit requirement.txt
- Make migrations + migrate
- Run server and check, add items to models manually from admin panel
- Add str function to models to make them seen other than an object
- Add MEDIA_URl and MEDIA_ROOT to seetings.py and edit urls.py. Create media_root folder
- Edit models.py for uploading images (paths)
- For generating slug create signals.py file, and add a function to apps.py
- Edit signals.py
- Create Comment, Like and View classes in models. Make migrations + migrate
- Create forms.py. Add PostForm and CommentForm
- Edit views -> post_list
- Edit settings.py ->TEMPLATES
- 'DIRS': [BASE_DIR, "templates"]
- Create folder templates under src folder and create file base.html
- Create folders templates/blog under blog folder and create post_list.html
- Create post_list function in views, edit both urls.py files
- Create post_create function in views.(❗️ adding files, getting author info )
- Create post_create.html and edit urls.py
- uuid -> create file utils.py. Inside create a 10 char-long unique id to improve slugify
- Create post_details function in views, edit urls.py, create post_details.html file
- Pace post titles in post_list page anchor to link user to post_detail page
- Add update and delete posts as above
- Apply bootstrap starter template to base.html
- Create navbar.html under src/templates
- Include navbar in base.html
- Create folders static/blog under application (blog) and create main.css file. (This is sth django wants)
- Add main.css file's link to head section of base.html and add {% load static %} on top
- Edit settings.py as
- STATICFILES_DIRS = [BASE_DIR / "static"]
- Apply a card style to post_list page with bootstrap.
- Get a kit script from fontawesome and apply to base.html to icons for comment, like and view
- Add functions to Post class in models.py to retrieve count of comments, likes and views
- Import CommentForm to views and add comment to post_detail function
- Add a method to Post class to retrieve all the comments of a post
- Display all the comments of a post using a for loop in post_detail page, and add a form to the same page to get comments from the user
- Import Like to views + add a like function + add like func to urls + create a form in post_detail.html (❗️ Note the action url)
- Add an if statement to post_detail.html do display delete and update buttons. If the user is the author, he should see update & delete buttons for his own post
- Now the problem is that a user can reach delete & update pages to any post by typing the url path to address bar. A temporary solution below. After using authentication we will change the way we do it.
- Install HttpResponse from django.http in views and add an if statement to post_update and post_delete as
- if request.user.id != obj.author.id
- return HttpResponse("You are not authorized")
- Install django-crispy-forms with pip and add crispy_forms to INSTALLED_APPS in settings.py. This third party app is for styling forms w bootstrap.
- Edit the detail, create, update and delete pages as follows:
- add {% load crispy_forms_tags %}
- and change previously form.as_p to form|crispy
- Style these pages with bootstrap
- Create users app + add the new app to INSTALLED_APPS in settings.py
- Create a Profile class in users > models add fields. Add a function to point the path to save the uploaded profile pictures of the user
- pip freeze > requiremets.txt
- makemigrations & migrate
- Register Profile in users > admin.py
- In order to automatically create a userf profile just after adding a user create a signals.py file (see the code)
- Add a ready method in users > apps.py to make signals.py take effect