Site icon JnPnote

Following Django Tutorial (CRM)-Part15

This post is for myself to remember how to build Django project.
I did follow the tutorial from the JustDjango Learn website free tutorial.
And this is the fourth tutorial named Getting Started With Django.
I am not going over all the details and descriptions for each part. There are good explanations on video of the JustDjango Learn. So, visit their site and try their tutorials if you need more details. Also, the orders of this post and their video might be different because I put things first what I think should come first.

I am doing this on Windows 10 with just Windows PowerShell. Not using virtual machines at all.

1. Install and basic settings for new package

pip install django-crispy-forms
pip freeze > requirements.txt
pip install crispy-tailwind

2. use of crispy form

{% extends 'base.html' %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">

	<div class="py-5 border-b border-gray-200 mt-5">
		<a class="hover:text-blue-500" href="{% url 'signup' %}">
			Don't have an account?
		</a>
	</div>
	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Login
		</button>
	</form>
	<div class="py-5 border-t border-gray-200 mt-5">
		<a class="hover:text-blue-500" href="{% url 'reset-password' %}">
			Forgot password?
		</a>
	</div>
</div>

{% endblock content %}

3. edit all the forms in the project

{% extends 'base.html' %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<h1 class="text-4xl text-gray-800">Enter your new password</h1>

	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Confirm new password
		</button>
	</form>
	<div class="py-5 border-t border-gray-200 mt-5">
		<a class="hover:text-blue-500" href="{% url 'signup' %}">
			Already have an account?
		</a>
	</div>
</div>


{% endblock content %}
{% extends 'base.html' %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<h1 class="text-4xl text-gray-800">Reset your password</h1>

	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Reset Password
		</button>
	</form>
	<div class="py-5 border-t border-gray-200 mt-5">
		<a class="hover:text-blue-500" href="{% url 'login' %}">
			Already have an account?
		</a>
	</div>	
</div>


{% endblock content %}
{% extends 'base.html' %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Signup
		</button>
	</form>
	<div class="py-5 border-t border-gray-200 mt-5">
		<a class="hover:text-blue-500" href="{% url 'login' %}">
			Already have an account?
		</a>
	</div>
</div>

{% endblock content %}
{% extends "base.html" %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<a class="hover:text-blue-500" href="{% url 'leads:lead-list' %}">
		Go back to leads
	</a>
	<div class="py-5 border-t border-gray-200">
		<h1 class="text-4xl text-gray-800">Create a new lead</h1>
	</div>
	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Submit
		</button>
	</form>
</div>
	
{% endblock content %}
{% extends "base.html" %}
{% load tailwind_filters %}

{% block content %}

<section class="text-gray-600 body-font overflow-hidden">
	<div class="container px-5 py-24 mx-auto">
		<div class="lg:w-4/5 mx-auto flex flex-wrap">
			<div class="lg:w-1/2 w-full lg:pr-10 lg:py-6 mb-6 lg:mb-0">
				<h2 class="text-sm title-font text-gray-500 tracking-widest">
					LEAD
				</h2>
				<h1 class="text-gray-900 text-3xl title-font font-medium mb-4">
					{{ lead.first_name }} {{ lead.last_name }}
				</h1>
				<div class="flex mb-4">
					<a href="{% url 'leads:lead-detail' lead.pk %}" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
						Description
					</a>
					<a href="{% url 'leads:lead-category-update' lead.pk %}" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
						Category
					</a>
					<a href="{% url 'leads:lead-update' lead.pk %}" class="flex-grow text-indigo-500 border-b-2 border-indigo-500 py-2 text-lg px-1">
						Update Details
					</a>
				</div>
				<form method="post">
					{% csrf_token %}
					{{ form|crispy }}
					<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
						Submit
					</button>
				</form>
				<div class="mt-5 py-5 border-t border-gray-200">
					<a href="{% url 'leads:lead-delete' lead.pk %}" class="w-1/2 mt-3 text-white bg-indigo-500 border-0 py-2 px-6 focus:outline-none hover:bg-indigo-600 rounded">
						Delete
					</a>
				</div>
			</div>
			<img alt="ecommerce" class="lg:w-1/2 w-full lg:h-auto h-64 object-cover object-center rounded" src="https://dummyimage.com/400x400">
		</div>
	</div>
</section>
{% endblock content %}
{% extends "base.html" %}
{% load tailwind_filters %}

{% block content %}

<section class="text-gray-600 body-font overflow-hidden">
	<div class="container px-5 py-24 mx-auto">
		<div class="lg:w-4/5 mx-auto flex flex-wrap">
			<div class="lg:w-1/2 w-full lg:pr-10 lg:py-6 mb-6 lg:mb-0">
				<h2 class="text-sm title-font text-gray-500 tracking-widest">
					LEAD
				</h2>
				<h1 class="text-gray-900 text-3xl title-font font-medium mb-4">
					{{ lead.first_name }} {{ lead.last_name }}
				</h1>
				<div class="flex mb-4">
					<a href="{% url 'leads:lead-detail' lead.pk %}" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
						Description
					</a>
					<a href="{% url 'leads:lead-category-update' lead.pk %}" class="flex-grow text-indigo-500 border-b-2 border-indigo-500 py-2 text-lg px-1">
						Category
					</a>
					<a href="{% url 'leads:lead-update' lead.pk %}" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
						Update Details
					</a>
				</div>
				<form method="post">
					{% csrf_token %}
					{{ form|crispy }}
					<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
						Submit
					</button>
				</form>
			</div>
			<img alt="ecommerce" class="lg:w-1/2 w-full lg:h-auto h-64 object-cover object-center rounded" src="https://dummyimage.com/400x400">
		</div>
	</div>
</section>
{% endblock content %}
{% extends "base.html" %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<a class="hover:text-blue-500" href="{% url 'leads:lead-list' %}">
		Go back to leads
	</a>
	<div class="py-5 border-t border-gray-200">
		<h1 class="text-3xl text-gray-800">
			Are you sure you want to delete this lead?
		</h1>
	</div>
	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Submit
		</button>
	</form>
</div>
	
{% endblock content %}
{% extends "base.html" %}

{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<a class="hover:text-blue-500" href="{% url 'agents:agent-list' %}">
		Go back to agents
	</a>
	<div class="py-5 border-t border-gray-200">
		<h1 class="text-4xl text-gray-800">Create a new agent</h1>
	</div>
	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Submit
		</button>
	</form>
</div>
	
{% endblock content %}
{% extends "base.html" %}
{% load tailwind_filters %}

{% block content %}

<section class="text-gray-600 body-font overflow-hidden">
	<div class="container px-5 py-24 mx-auto">
		<div class="lg:w-4/5 mx-auto flex flex-wrap">
			<div class="lg:w-1/2 w-full lg:pr-10 lg:py-6 mb-6 lg:mb-0">
				<h2 class="text-sm title-font text-gray-500 tracking-widest">
					AGENT
				</h2>
				<h1 class="text-gray-900 text-3xl title-font font-medium mb-4">
					{{ agent.user.username }}
				</h1>
				<div class="flex mb-4">
					<a href="{% url 'agents:agent-detail' agent.pk %}" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
						Overview
					</a>
					<a class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
						Reviews
					</a>
					<a href="{% url 'agents:agent-update' agent.pk %}" class="flex-grow text-indigo-500 border-b-2 border-indigo-500 py-2 text-lg px-1">
						Update Details
					</a>
				</div>
				<form method="post">
					{% csrf_token %}
					{{ form|crispy }}
					<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
						Submit
					</button>
				</form>
				<div class="mt-5 py-5 border-t border-gray-200">
					<a href="{% url 'agents:agent-delete' agent.pk %}" class="w-1/2 mt-3 text-white bg-indigo-500 border-0 py-2 px-6 focus:outline-none hover:bg-indigo-600 rounded">
						Delete
					</a>
				</div>
			</div>
			<img alt="ecommerce" class="lg:w-1/2 w-full lg:h-auto h-64 object-cover object-center rounded" src="https://dummyimage.com/400x400">
		</div>
	</div>
</section>
{% endblock content %}
{% extends "base.html" %}
{% load tailwind_filters %}

{% block content %}

<div class="max-w-lg mx-auto">
	<a class="hover:text-blue-500" href="{% url 'agents:agent-list' %}">
		Go back to agents
	</a>
	<div class="py-5 border-t border-gray-200">
		<h1 class="text-3xl text-gray-800">
			Are you sure you want to delete this agent?
		</h1>
	</div>
	<form method="post" class="mt-5">
		{% csrf_token %}
		{{ form|crispy }}
		<button type="submit" class="w-full text-white bg-blue-500 hover:bg-blue-600 px-3 py-2 rounded-md">
			Submit
		</button>
	</form>
</div>
{% endblock content %}

4. add more fields on Lead

description = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
phone_number = models.CharField(max_length=20)
email = models.EmailField()
lead = form.save(commit=False)
lead.organisation = self.request.user.userprofile
lead.save()

5. assign correct values into set as static values

{{ lead.description }}

6. log out redirect

LOGOUT_REDIRECT_URL = "/"

done for this post

Exit mobile version