A beginners course for Django

Overview

JustDjango

The Definitive Django Learning Platform.

Getting started with Django

This is the code from the course "Getting Started With Django", found on YouTube and JustDjango


Getting Started

To run this project you will need to set your environment variables.

  1. Create a new file named .env inside the djcrm folder
  2. Copy all of the variables inside djcrm/.template.env and assign your own values to them
  3. Run export READ_DOT_ENV_FILE=True inside your terminal so that your environment variables file will be read.

Other places you can find us:

YouTube Twitter

Comments
  • Error when updating Lead category

    Error when updating Lead category

    I have deployed the script successfully but I noticed an issue when trying to update lead category.

    Any ideas ?

    Error:

    Category matching query does not exist. Request Method: POST Request URL: http://127.0.0.1:8000/leads/1/category/ Django Version: 3.1.4 Exception Type: DoesNotExist Exception Value: Category matching query does not exist. Exception Location: C:\Users\MeCD\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py, line 429, in get Python Executable: C:\Users\MeCD\AppData\Local\Programs\Python\Python39\python.exe Python Version: 3.9.2 Python Path: ['C:\getting-started-with-django-main', 'C:\Users\MeCD\AppData\Local\Programs\Python\Python39\python39.zip', 'C:\Users\MeCD\AppData\Local\Programs\Python\Python39\DLLs', 'C:\Users\MeCD\AppData\Local\Programs\Python\Python39\lib', 'C:\Users\MeCD\AppData\Local\Programs\Python\Python39', 'C:\Users\MeCD\AppData\Local\Programs\Python\Python39\lib\site-packages'] Server time: Tue, 27 Apr 2021 14:00:29 +0000

    opened by ZackElias 2
  • Server Error (500) >> OperationalError at /login/ no such table: leads_user

    Server Error (500) >> OperationalError at /login/ no such table: leads_user

    I've followed this tutorial to the last until the project is deployed where my issue arises. After deploying the project with DEBUG=FALSE, I get a Server Error (500) when I login. I then changed the debug setting to true so I can see the error message and it says OperationalError at /login/ no such table: leads_user. I viewed the database schema on my terminal and the table leads_user is present. Running migrations also doesn't solve it.

    I finally tried logging in through your deployed project(https://crm.justdjango.com/) and I got a Server Error (500) so I'm assuming this is a problem a lot have faced. Anyone know what the fix is?

    opened by sir-meee 2
  • AbstractUser in Model

    AbstractUser in Model

    Hey Matthew I learn about your Youtube Video "Getting Started with Django". If i make the User Model with AbstractUser i never can login in my admin.

    • I registrated the leads app in my Settings.
    • I testet the config with and without AUTH_USER_MODEL = 'leads.User'

    but it never works. What i make false?

    # leads/model.py
    from django.db import models
    from django.contrib.auth.models import AbstractUser
    
    
    class User(AbstractUser):
        pass
    
    class Lead (models.Model):
        first_name = models.CharField(max_length=50) 
        last_name = models.CharField(max_length=50) 
        age = models.IntegerField(default=0) 
        agent = models.ForeignKey("Agent", on_delete=models.CASCADE) 
    
        def __str__(self):
            return f"{self.first_name} {self.last_name}"
    
    class Agent(models.Model):
        user = models.OneToOneField(User, on_delete=models.CASCADE)
        first_name = models.CharField(max_length=20)
        last_name = models.CharField(max_length=20)
    
        def __str__(self):
            return self.user.email
    
    # leads/admin.py
    from django.contrib import admin
    from .models import User, Lead, Agent
    
    class LeadAdmin(admin.ModelAdmin):
        model = Lead
        list_display = ('first_name', 'last_name', 'age', 'agent')
    
    admin.site.register(User)
    admin.site.register(Lead, LeadAdmin)
    admin.site.register(Agent)
    
    (venv) CRM_Tutorial> python3.exe .\manage.py 
    runserver
    Watching for file changes with StatReloader
    Performing system checks...
    
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\threading.py", line 954, in _bootstrap_inner
        self.run()
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\threading.py", line 892, in run
        self._target(*self._args, **self._kwargs)
      File "C:\Users\Christoph\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\utils\autoreload.py", line 53, in wrapper 
        fn(*args, **kwargs)
      File "C:\Users\Christoph\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
        self.check(display_num_errors=True)
      File "C:\Users\Christoph\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\management\base.py", line 442, in check
        raise SystemCheckError(msg)
    django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
    
    ERRORS:
    auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'User.groups'.
            HINT: Add or change a related_name argument to the definition for 'User.groups' or 'User.groups'.
    auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
            HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'User.user_permissions'.
    leads.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'User.groups'.
            HINT: Add or change a related_name argument to the definition for 'User.groups' or 'User.groups'.
    leads.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
            HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'User.user_permissions'.
    
    System check identified 4 issues (0 silenced).
    

    Best regards Christoph

    opened by christophschoeni 1
  • AttributeError at /signup/

    AttributeError at /signup/

    hi thank you for such an awsome tutorial, but i got stuck while creating signup, i been following ur video, you got the same error and u fixed it with User = get**model();

    but even after following you, i still get that error, ########################################################################################## leads/forms.py

    from django import forms from .models import Lead from django.contrib.auth import get_user_model from django.contrib.auth.forms import UserCreationForm, UsernameField

    User = get_user_model()

    class LeadModelForm(forms.ModelForm): class Meta: model = Lead fields =( 'first_name', 'last_name', 'age', 'agent' )

    class LeadForm(forms.Form): first_name = forms.CharField() last_name = forms.CharField() age = forms.IntegerField(min_value=0)

    class CustomUserCreationForm(UserCreationForm): class meta: model = User fields = {"username",} field_classes = {'username': UsernameField} ############################################################################### djcrm/urls.py

    from django.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.contrib.auth.views import LoginView, LogoutView from django.urls import path, include from leads.views import landing_page, LandingPageView, SignupView

    urlpatterns = [ path('admin/', admin.site.urls), # path('', landing_page, name='landing-page'), path('', LandingPageView.as_view(), name='landing-page'), path('leads/', include('leads.urls', namespace="leads")), path('login/', LoginView.as_view(), name='login'), path('signup/', SignupView.as_view(), name='signup'), path('logout/', LogoutView.as_view(), name='logout') ]

    if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) ############################################################################## leads/views.py

    from django.shortcuts import render, redirect, reverse #from django.contrib.auth.forms import UserCreationForm from django.core.mail import send_mail from django.http import HttpResponse from .models import Lead, Agent from .forms import LeadForm, LeadModelForm,CustomUserCreationForm from django.views import generic

    CRUD+L create retrieve update delete + list

    class SignupView(generic.CreateView): template_name = "registration/signup.html" form_class = CustomUserCreationForm

    def get_success_url(self):
        return reverse("login")
    

    class LandingPageView(generic.TemplateView): template_name = "landing.html"

    def landing_page(request): return render(request, "landing.html")

    class LeadListView(generic.ListView): template_name = "leads/lead_list.html" queryset = Lead.objects.all() context_object_name = "leads"

    def lead_list(request): #return HttpResponse("hello_world") leads = Lead.objects.all() context = { "leads": leads } return render(request, "leads/lead_list.html", context)

    class LeadDetailView(generic.DetailView): template_name = "leads/lead_detail.html" queryset = Lead.objects.all() context_object_name = "lead"

    def lead_detail(request, pk): lead = Lead.objects.get(id=pk) context = { "lead": lead } return render(request, "leads/lead_detail.html", context)

    class LeadCreateView(generic.CreateView): template_name = "leads/lead_create.html" form_class = LeadModelForm

    def get_success_url(self):
        return reverse("leads:lead-list")
    
    def form_valid(self, form):
        #trigger email
        send_mail(
            subject="hello new lead entry",
            message="please check admin console, new lead entry",
            from_email="[email protected]",
            recipient_list=["[email protected]","[email protected]"]
        )
        return super(LeadCreateView, self).form_valid(form)
    

    def lead_create(request): form = LeadModelForm()

    if request.method == "POST":
        print('Receiving a post requet')
        form =LeadModelForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("/leads")
    context = {
        "form": form
    }
    return render(request, "leads/lead_create.html", context)
    

    class LeadUpdateView(generic.UpdateView): template_name = "leads/lead_update.html" queryset = Lead.objects.all() form_class = LeadModelForm

    def get_success_url(self):
        return reverse("leads:lead-list")
    

    def lead_update(request, pk): lead = Lead.objects.get(id=pk) form = LeadModelForm(instance=lead) if request.method == "POST": form =LeadModelForm(request.POST, instance=lead) if form.is_valid(): form.save() return redirect("/leads") context = { "form": form, "lead": lead } return render(request, "leads/lead_update.html", context)

    def lead_delete(request, pk): lead = Lead.objects.get(id=pk) lead.delete() return redirect("/leads")

    class LeadDeleteView(generic.DeleteView): template_name = "leads/lead_delete.html" queryset = Lead.objects.all()

    def get_success_url(self):
        return reverse("leads:lead-list")
    

    ############################################################################################ traceback

    Environment:

    Request Method: POST Request URL: http://127.0.0.1:8000/signup/

    Django Version: 3.1.4 Python Version: 3.9.2 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'leads'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

    Traceback (most recent call last): File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\views\generic\base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\views\generic\base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\views\generic\edit.py", line 172, in post return super().post(request, *args, **kwargs) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\views\generic\edit.py", line 141, in post if form.is_valid(): File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\forms\forms.py", line 177, in is_valid return self.is_bound and not self.errors File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\forms\forms.py", line 172, in errors self.full_clean() File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\forms\forms.py", line 376, in full_clean self._post_clean() File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\contrib\auth\forms.py", line 124, in _post_clean super()._post_clean() File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\forms\models.py", line 405, in _post_clean self.instance.full_clean(exclude=exclude, validate_unique=False) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\db\models\base.py", line 1216, in full_clean self.clean() File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\contrib\auth\models.py", line 365, in clean self.email = self.class.objects.normalize_email(self.email) File "C:\Users\repairmen\Desktop\crm\getting-started-with-django\env\lib\site-packages\django\db\models\manager.py", line 187, in get raise AttributeError(

    Exception Type: AttributeError at /signup/ Exception Value: Manager isn't available; 'auth.User' has been swapped for 'leads.User' Screenshot (797)

    opened by r3pairmen 0
  • Missing styles.css after building styles with modern django-tailwind package (v3.1.1)

    Missing styles.css after building styles with modern django-tailwind package (v3.1.1)

    The current version of django-tailwind (3.1.1) package builds styles.css into this folder:

    theme/static/css/dist/styles.css
    

    The previous version used in the video (Intermediate Django - Lesson 19.TailwindCSS Improvements) builds into this one:

    theme/static/css/styles.css
    

    So, after deploying it into production you'll get such an error (fullscreen): And Server Error (500) on the prod.

    Solution: Fix a link to styles.css inside templates/base.html to be this:

    <link  href="{% static 'css/dist/styles.css' %}" rel="stylesheet">
    

    p.s. I also had theme/static/css/dist/styles.css missing from a corresponding git commit at first, because it had turned out to be ignored by .gitignore.

    The solution: Add line !/theme/static/css/dist to .gitignore

    opened by paulrogov 0
  • The form of the LeadCreateView provides access to all the agents

    The form of the LeadCreateView provides access to all the agents

    The form of the LeadCreateView is bugged.

    It provides access to all the agents, including those from other organizations (created by other organizer users).

    fullscreen

    opened by paulrogov 1
  • "enctype" attribute is missing on the form inside lead_create.html

    It's impossible to load a profile picture while creating a new lead.

    The reason: form attribute enctype="multipart/form-data" is missing inside the lead_create.html.

    opened by paulrogov 0
  • AgentUpdateView not working

    AgentUpdateView not working

    Everything in the application from the tutorial so far (about to get into deployment) works perfectly except for UpdateAgentView. I've copy/pasted straight from this GitHub, and it still won't update the information for the agents. The form just goes back to agent-list with no changes on the front end, and no changes in the Agent or User table.

    I've seen a few others post about this same issue on the YouTube video.

    With that being said, what an amazing tutorial, and I've very appreciative of your work!

    My best, Michael

    opened by Bowiemb 8
Owner
JustDjango
The Definitive Django Learning Platform
JustDjango
Web APIs for Django. 🎸

Django REST framework Awesome web-browsable Web APIs. Full documentation for the project is available at https://www.django-rest-framework.org/. Fundi

Encode 24.7k Jan 3, 2023
Phoenix LiveView but for Django

Reactor, a LiveView library for Django Reactor enables you to do something similar to Phoenix framework LiveView using Django Channels. What's in the

Eddy Ernesto del Valle Pino 526 Jan 2, 2023
Source code for Django for Beginners 3.2

The official source code for https://djangoforbeginners.com/. Available as an ebook or in Paperback. If you have the 3.1 version, please refer to this

William Vincent 10 Jan 3, 2023
All course materials for the Zero to Mastery Deep Learning with TensorFlow course.

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.

Daniel Bourke 3.4k Jan 7, 2023
A Web Scraper built with beautiful soup, that fetches udemy course information. Get udemy course information and convert it to json, csv or xml file

Udemy Scraper A Web Scraper built with beautiful soup, that fetches udemy course information. Installation Virtual Environment Firstly, it is recommen

Aditya Gupta 15 May 17, 2022
A course-planning, course-map rendering and GPA-calculation web service, designed for the SFU (Simon Fraser University) student.

SFU Course Planner What is the overall goal of the project (i.e. what does it do, or what problem is it solving)? As the title suggests, this project

Ash Peng 1 Oct 21, 2021
Course material for the Multi-agents and computer graphics course

TC2008B Course material for the Multi-agents and computer graphics course. Setup instructions Strongly recommend using a custom conda environment. Ins

null 16 Dec 13, 2022
All exercises done during the Python 3 course in the Video Course (World 1, 2 and 3)

Python3-cursoemvideo-exercises - All exercises done during the Python 3 course in the Video Course (World 1, 2 and 3)

Renan Barbosa 3 Jan 17, 2022
Course-parsing - Parsing Course Info for NIT Kurukshetra

Parsing Course Info for NIT Kurukshetra Overview This repository houses code for

Saksham Mittal 3 Feb 3, 2022
Algorithm and Structured Programming course project for the first semester of the Internet Systems course at IFPB

Algorithm and Structured Programming course project for the first semester of the Internet Systems course at IFPB

Gabriel Macaúbas 3 May 21, 2022
Python IDE for beginners

Thonny Thonny is a Python IDE meant for learning programming. End users See https://thonny.org and wiki for more info. Contributors Contributions are

Thonny, Python IDE for beginners 2.1k Jan 2, 2023
Classic Papers for Beginners and Impact Scope for Authors.

There have been billions of academic papers around the world. However, maybe only 0.0...01% among them are valuable or are worth reading. Since our limited life has never been forever, TopPaper provide a Top Academic Paper Chart for beginners and reseachers to take one step faster.

Qiulin Zhang 228 Dec 18, 2022
Description Basic Recon tool for beginners. Especially those who faces issue on how to recon or what all tools to use

Description Basic Recon tool for beginners. Especially those who faces issue on how to recon or what all tools to use. Will try to add atleast 10 more tools currently use 7 sources to gather domains.Currenlty uses below mentioned tools and also sort live domains using HttpX.

Harinder Singh 7 Jan 3, 2022
This repository contains Python Projects for Beginners as well as for Intermediate Developers built by Contributors.

Python Projects {Open Source} Introduction The repository was built with a tree-like structure in mind, it contains collections of Python Projects. Mo

Gaurav Pandey 115 Apr 30, 2022
step by step guide for beginners for getting started with open source

Step-by-Step Guide for beginners for getting started with Open-Source Here The Contribution Begins ?? If you are a beginner then this repository is fo

Arpit Jain 66 Jan 3, 2023
An open-source Python project series where beginners can contribute and practice coding.

Python Mini Projects A collection of easy Python small projects to help you improve your programming skills. Table Of Contents Aim Of The Project Cont

Leah Nguyen 491 Jan 4, 2023
Small projects for python beginners.

Python Mini Projects For Beginners I recently started doing the #100DaysOfCode Challenge in Python. I've used Python before, but I had switched to JS

Sreekesh Iyer 10 Dec 12, 2022
A simple hangman game for beginners trying to learn python

Hangman Game This is a simple hangman game for beginners trying to learn python. I have tried to keep it as simply as possible. Sample output Here is

null 1 Oct 13, 2021
Discord-Bot - Bot using nextcord for beginners

Discord-Bot Bot using nextcord for beginners! Requirements: 1 :- Install nextcord by typing "pip install nextcord" Thats it! You can use this code any

INFINITE_. 3 Jan 10, 2022
Faza - Faza terminal, Faza help to beginners for pen testing

Faza terminal simple tool for pen testers Use small letter only for commands Don't use space after command 'help' for more information Installation gi

Ag3ntQ 5 Feb 20, 2022