<repo_name>ANSHUL-original/Top-SeCret<file_sep>/main/urls.py
from django.conf.urls import url
from .views import about,home,contactus,single,posts,delete_v,edit


#login views import
from .views import login_v,logout_v,register

#website urls
from .views import arun,contact,index,trip,confirm


urlpatterns = [
    url(r'^arun/$',arun,name='arun'),
    url(r'^contact/$',contact,name='contact'),
    url(r'^index/$',index,name='index'),
    url(r'^trip/$',trip,name='trip'),
    url(r'^confirm/$', confirm,name='confirm'), 




	url(r'^register/$', register, name='register'),
	url(r'^logout/$', logout_v, name='logout_v'),
	

	url(r'^single/(?P<id>\d+)/$',single,name='single'),
	url(r'^edit/(?P<id>\d+)/$',edit,name='edit'),
    url(r'^delete/(?P<id>\d+)/$',delete_v,name='delete_v'),
    url(r'^posts/$',posts,name='posts'),
    url(r'^about/$', about, name='about'),
    url(r'^contactus/$', contactus, name='contactus'),
    url(r'^home/$', home, name='home'),

    url(r'^$', login_v, name='login_v')
]<file_sep>/admin.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin

from. models import Post,T_Model

# Register your models here.
class PostAdmin(admin.ModelAdmin):
	list_display = ['name','email','phone','profession']
	search_fields = ['name','email']

class TestAdmin(admin.ModelAdmin):
	list_display = ['name','email','contact','city']
	search_fields = ['name', 'phone']
admin.site.register(Post, PostAdmin)	

admin.site.register(T_Model, TestAdmin)	
<file_sep>/templates/posts.html
{% extends "base.html" %}

{% block content %}

	<header>
		<title>post title</title>
	</header>
	<h3>posts</h3>
	{% for obj in obj_list %}
		<div style="text-align:center;color:blue;padding:10px">
			<p>{{ obj.id }}</p> 
			<a href="/single/{{ obj.id }}"><h4>{{ obj.name }}</h4></a>	
		
			<h5>{{ obj.email }}</h5>
			<h6>{{ obj.phone }}</h6>
			<h6>{{ obj.profession }}</h6>
			<br><br><br><br>
		</div>
	{% endfor %}	
	
{% endblock content %}<file_sep>/main/models.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models

# Create your models here.
class Post(models.Model):
	name=models.CharField(max_length=50)
	email= models.EmailField(max_length=50)
	phone= models.CharField(max_length=50)
	profession= models.CharField(max_length=50)

class T_Model(models.Model):
	name= models.CharField(max_length=30)
	email= models.CharField(max_length=30) 
	contact =models.CharField(max_length=15)
	city = models.CharField(max_length=15)
	#nationality = models.CharField(max_length=20) <file_sep>/templates/single.html
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}

	<header>
		<title>single title</title>
	</header>
	<h2>single page {{ instance.id }}</h3>

	<p>{{ instance.name }}</p>
	<p>{{ instance.email }}</p>
	<p>{{ instance.phone }}</p>
	<p>{{ instance.profession }}</p>

	<a href="/edit/{{ instance.id }}">Edit</a>
	<a href="/delete/{{ instance.id }}">Delete</a>

	<form method="POST" action="">{% csrf_token %}
		{{ form|crispy }}
		<input type="submit" name="submit">
	</form>
	
{% endblock content %}<file_sep>/main/forms.py
from django import forms
from .models import Post
from django.contrib.auth import ( authenticate,
	get_user_model,
	login,
	logout,
	)

from .models import T_Model
class NPostForm(forms.Form):
	name=forms.CharField()
	email= forms.CharField()
	phone= forms.CharField()
	profession= forms.CharField()

class MPostForm(forms.ModelForm):
	class Meta:
		model = Post
		fields = [
			'name',
			'email',
			'phone',
			'profession'
		] 

#login forms
User = get_user_model()#?

class UserLoginForm(forms.Form):
	username= forms.CharField()
	password= forms.CharField(widget=forms.PasswordInput)

class UserRegisterForm(forms.ModelForm):
	password = forms.CharField(widget=forms.PasswordInput)
	confirm_password = forms.CharField(widget=forms.PasswordInput)

	class Meta:
		model = User 
		fields = [
			'username',
			'email',
			'password',
			'confirm_password',
		]
class T_Form(forms.ModelForm):
	class Meta:
		model = T_Model
		fields = ['name' ,'email','contact', 'city',]<file_sep>/main/views.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render,redirect,get_object_or_404
from .models import Post
from .forms import NPostForm,MPostForm
from django.contrib.auth import ( authenticate,
	get_user_model,
	login,
	logout,
	)

from .forms import UserRegisterForm,UserLoginForm
from .forms import T_Form

from .models import T_Model
# Create your views here.
#normal form
def home(request):
	if request.user.is_authenticated():
		form= NPostForm(request.POST or None)
		if form.is_valid():
			name= form.cleaned_data.get('name')
			email=form.cleaned_data.get('email')
			phone=form.cleaned_data.get('phone')
			profession= form.cleaned_data.get('profession')

			instance = Post()
			instance.name=name
			instance.email=email
			instance.phone=phone
			instance.profession=profession
			instance.save()

			form = NPostForm()
	context = {
		'form':form
	}
	return render(request, "home.html", context)

#Model Form
def about(request):
	if request.user.is_authenticated():
		form = MPostForm(request.POST or None)
		if form.is_valid():
			new_post= form.save(commit=False)
			new_post=form.save()

			form=MPostForm()
	context = {
		'form':form
	}
	return render(request, "about.html", context)

def contactus(request):	
	if request.user.is_authenticated():
		return render(request, "contactus.html",{})


#website forms
def trip(request):
	form = T_Form(request.POST or None)
	if form.is_valid():
		new_post= form.save(commit=False)
		new_post=form.save()

		return redirect('/confirm/')
	context = {
		'form':form
	}
	return render(request, "trip.html", context)


#single,posts,edit,delete_v
def single(request ,id=None):
	if request.user.is_authenticated():
		instance=get_object_or_404(Post, id=id)
		context = {
			'instance':instance
		}
		return render(request, 'single.html', context)

def posts(request):
	if request.user.is_authenticated():
		query= Post.objects.all()
		context= {
			'obj_list':query
		}
		return render(request, 'posts.html', context)

def edit(request, id=None):
	if request.user.is_authenticated():
		ins=get_object_or_404(Post, id=id)#?
		form = MPostForm(request.POST or None,instance=ins)
		if form.is_valid():
			up_post = form.save(commit=False)
			up_post.save()
			return redirect('/single/'+id)
		context = {
			'form':form
		}
		return render(request, "edit.html", context)
def delete_v(request, id=None):
	if request.user.is_authenticated():
		instance=get_object_or_404(Post,id=id)	#?
		instance.delete()
		return redirect('/posts/')

#login views

def login_v(request):
	form = UserLoginForm(request.POST or None)
	if form.is_valid():
		username = form.cleaned_data.get('username')
		password = form.cleaned_data.get('password')
		user = authenticate(username=username, password=password)
		try:
			login(request, user)
			return redirect('/home/')
		except:
			return redirect('/register/')
	context = {
		'form':form
	}
	return render(request, 'login.html' ,context)

def register(request):
	form= UserRegisterForm(request.POST or None)
	if form.is_valid():
		usr= form.save(commit=False)
		password= form.cleaned_data.get('<PASSWORD>')
		confirm_password= form.cleaned_data.get('confirm_password')
		if password == confirm_password:
			usr.set_password(password)
			usr.save()

		user= authenticate(username=usr.username, password=<PASSWORD>)
		login(request,user)
		return redirect ('/home/')
	context = {
		'form':form
	}
	return render(request, 'register.html', context)

def logout_v(request):
	if request.user.is_authenticated():
		logout(request)
		return redirect('/')



#website views
def arun(request):
	return render(request, 'arun.html', {})

def index(request):
	return render(request, 'index.html', {})
def contact(request):
	return render(request, 'contact.html', {})
def confirm(request):
	return render(request, 'confirm.html',{})