Skip to content

Commit

Permalink
new updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit0417 committed Feb 27, 2022
1 parent 990b18a commit 37efd29
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 12 deletions.
Binary file modified todolist/base/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified todolist/base/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified todolist/base/__pycache__/views.cpython-310.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.2 on 2022-02-27 06:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('base', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='task',
old_name='descripton',
new_name='description',
),
]
Binary file not shown.
2 changes: 1 addition & 1 deletion todolist/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Task(models.Model):
user = models.ForeignKey(User, on_delete = models.CASCADE, null = True, blank = True)
title =models.CharField(max_length= 200)
descripton = models.TextField(null = True, blank = True)
description = models.TextField(null = True, blank = True)
complete =models.BooleanField(default=False)
create = models.DateTimeField(auto_now_add=True)

Expand Down
4 changes: 3 additions & 1 deletion todolist/base/templates/base/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ <h3>Login</h3>
{{form.as_p}}
<input type="submit" value="Login">

</form>
</form>

<p>Don't have an account ? <a href="{% url 'register' %}">Register</a></p>
10 changes: 10 additions & 0 deletions todolist/base/templates/base/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h3>Register</h3>

<form method="POST">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Register">

</form>

<p>Already have an account ? <a href="{% url 'login' %}">Login</a></p>
3 changes: 2 additions & 1 deletion todolist/base/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path
from . views import TaskList ,TaskDetail, TaskCreate ,TaskUpdate , DeleteView , CustomLoginView
from . views import TaskList ,TaskDetail, TaskCreate ,TaskUpdate , DeleteView , CustomLoginView, RegisterPage
from django.contrib.auth.views import LogoutView

urlpatterns = [
path('login/', CustomLoginView.as_view(), name = 'login' ),
path('logout/', LogoutView.as_view(next_page ='login'), name = 'logout' ),
path('register/', RegisterPage.as_view(), name = 'register'),
path('', TaskList.as_view() , name = 'tasks'),
path('task/<int:pk>', TaskDetail.as_view() , name = 'task'),
path('task-create', TaskCreate.as_view() , name = 'task-create'),
Expand Down
36 changes: 27 additions & 9 deletions todolist/base/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from dataclasses import field, fields
from pickle import TRUE
from re import template
from sqlite3 import complete_statement
from django.http import HttpResponse

from django.shortcuts import redirect, render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView ,UpdateView ,DeleteView
from django.views.generic.edit import CreateView ,UpdateView ,DeleteView, FormView
from django.urls import reverse_lazy

from django.contrib.auth.views import LoginView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login

from . models import Task

Expand All @@ -22,6 +20,26 @@ class CustomLoginView(LoginView):
def get_success_url(self):
return reverse_lazy('tasks')


class RegisterPage(FormView):
template_name = 'base/register.html'
form_class = UserCreationForm
redirect_authenticated_user = True
success_url = reverse_lazy('tasks')

def form_valid(self, form):
user = form.save()
if user is not None:
login(self.request , user)
return super(RegisterPage , self).form_valid(form)

def get(self, *args ,**kwargs):
if self.request.user.is_authenticated:
return redirect('tasks')
return super(RegisterPage , self).get(*args , **kwargs)



class TaskList(LoginRequiredMixin,ListView):
model = Task
context_object_name = 'tasks'
Expand All @@ -40,7 +58,7 @@ class TaskDetail(LoginRequiredMixin,DetailView):

class TaskCreate(LoginRequiredMixin,CreateView):
model = Task
fields = ['title', 'descripton', 'complete']
fields = ['title', 'description', 'complete']
success_url = reverse_lazy('tasks')

def form_valid(self, form):
Expand All @@ -50,7 +68,7 @@ def form_valid(self, form):

class TaskUpdate(LoginRequiredMixin,UpdateView):
model = Task
fields = ['title', 'descripton', 'complete']
fields = ['title', 'description', 'complete']
success_url = reverse_lazy('tasks')

class DeleteView(LoginRequiredMixin,DeleteView):
Expand Down
Binary file modified todolist/db.sqlite3
Binary file not shown.

0 comments on commit 37efd29

Please sign in to comment.