Hello World, Welcome to ProjectsPlaza.com. Today we will discuss how to use annotate aggregation in Django. In this tutorial, we will fetch data from two different models. For example, I am creating a video sharing website like YouTube. I have two models. One is a channel and another is a video. Both models are joined with foreign keys. Now I want to fetch channels with videos count. I will do this with annotate aggregation.
Create Like Dislike System with Laravel Jquery Ajax
Hello World, Welcome to ProjectsPlaza.com Today we will create like dislike system using Laravel, jquery, and ajax. I will extend my previous tutorial Create a comment system with jquery ajax and Laravel. In this tutorial, we will save like and dislike counting in the database for a specific post. You can extend this system with user authentication. When users view the post detail page then like-dislike counting will also show for this post. I have divided this tutorial into the following steps:
Create LikeDislike Model
- Build Relationship between Post and LikeDislike Model
- Create a view for like and dislike
- Save like dislike counting on click
Create class based view in django 3
Hello World, Welcome to projects plaza.com. Today we will learn how to create a class-based view in Django 3. In this tutorial, we will render a simple template via class. Basically, there are two methods to load the view template in Django. One is a function-based view(FBV) and another is a class-based view(CBV). Class-based views were introduced in Django 1.7. The reason behind this was the proper structure, inheritance and the developer can customize the class-based view more than the function-based view.
- Create cbv.html in the templates folder in your app and add the following code.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CBV View</title> </head> <body> <h3>Hello World, This is class based view</h3> </body> </html>
- Open app/urls.py and add the following code in it
urlpatterns=[ ... path('cbv',TemplateView.as_view(template_name="cbv.html")) ]
Python example 3 – Solver number power
Hello World, Welcome to projectsplaza.com. In this example, we will calculate the power of the number. We will take the number and power from the user and calculate it with python function. We will do this in the following steps.
- get to input from the user
- calculate the number of power with
def power_multiply(): number=int(input('Enter the number ')) power=int(input('Enter the power ')) print(number**power) power_multiply()
Output of this example
Create comment system with jquery ajax and laravel 7
Hello World, Welcome to ProjectsPlaza.com. Today we will learn how to create a comment system with jQuery Ajax and Laravel 7. In this tutorial, we will save comments and show instantly with the total comments count. This gonna be a very interesting tutorial for me as well as for you (I hope). I have divided this tutorial into the following parts:
- Create a Post model
- Create a Comment model
- Define the hasMany relationship in Post Model
- Add dummy data for post
- Create a PostController and define a method for post list and post detail
- Create templates for post and post detail with comments and show data
- Setup route
- Add a comment with jquery ajax and show instantly
Change default auth login redirect in laravel 7
Hello World, Today we will learn how to change the default auth login redirect in Laravel 7. If you are using the Laravel authentication system then you will see that after successful login, you will be redirected on the ‘/home’ path. But if you want to change the default path then you need to change some code in the following file.
public const HOME = '/home';
public const HOME = '/your-path';
Count page views in laravel 7
Hello World, Today we will learn how to count page views in Laravel 7. In this tutorial, we simply count the page views whenever the user visits the page. Suppose we have a post detail page and we want to show how many times this post has been viewed by users. We will use shorthand Laravel query methods to solve this problem.
The above method will increase 1 every time. If you want to increase 2 or more then you can change the above code as follows.
Fetch data with model relationship in laravel 7
Hello World, Welcome to projectsplaza.com. Today we will discuss how we can fetch data with the model relationship in laravel 7. In this tutorial, we will create an example of hasMany and belongsTo model relationship.
Suppose you have a blog website and you want to fetch comments of a specific post on the post detail page. In this scenario, you should have two models, Post and Comment respectively. We know that a single post has many comments so we will define the hasMany relationship in the post model.
Python Example 2 – Summing Numbers
Hello World, Welcome to projectsplaza.com. In this tutorial, we will create a custom python function to show the sum of the provided numbers. This function takes a sequence of numbers and shows the sum of those numbers. This exercise helps you to understand numbers and function design.
Python Example 1 – Number guessing game with python
Hello World, Welcome to projectsplaza.com. Today we will discuss how to create a number guessing game with python. This tutorial is for python beginner. Python has three different numeric types: int, float, and complex. Most of the time, it is enough to know about int(for the whole number) and float(for fraction number). For this game, we will do the following steps
- Write a function guess_number that takes no arguments.
- When we run this function it will automatically choose the number between 0-50.
- Ask the user to guess what number has been chosen.
- Every time user guess a number, we will indicate the following:
- Too High
- Too Low
- Just Right
- If the user guesses the correct number then the program exit, otherwise the user is asked to try again.
- Programm will exist only if the user guesses the correct number.