0% found this document useful (0 votes)
14 views3 pages

P 9

Uploaded by

Kamal Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

P 9

Uploaded by

Kamal Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-----------------views.

py---------------

from django.shortcuts import render


from django.http import HttpResponse,HttpResponseRedirect,FileResponse
from app9.models import ProjectReg

def add_project(request):
submitted = False
if request.method == 'POST':
form = ProjectReg(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/add_project/?submitted=True')
else:
form = ProjectReg()
if 'submitted' in request.GET:
submitted = True
return render(request, 'pro_reg.html', {'form': form, 'submitted': submitted})

----------------------urls.py-----------------------------
from django.contrib import admin
from django.urls import path
from app9.views import add_project

urlpatterns = [
path('admin/', admin.site.urls),
path('add_project/',add_project),
]

-----------------templates ----------------
-------pro_reg.html-----
{% if submitted %}
<p class="success">
Project Registration is successful. Thank you.
</p>
{% else %}
<form action="" method="post" novalidate>
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
{% csrf_token %}
</form>
{% endif %}

---------------models.py--------------

from django.db import models


from django.forms import ModelForm

class Course(models.Model):
course_code=models.CharField(max_length=40)
course_name=models.CharField(max_length=100)
course_credits=models.IntegerField()

class Student(models.Model):
student_usn=models.CharField(max_length=20)
student_name=models.CharField(max_length=100)
student_sem=models.IntegerField()
enrolment=models.ManyToManyField(Course)
def __str__(self):
return self.student_name

class Project(models.Model):
student=models.ForeignKey(Student,on_delete=models.CASCADE)
topic=models.CharField(max_length=100)
languages=models.CharField(max_length=100)
duration=models.IntegerField()
def __str__(self):
return self.topic

class ProjectReg(ModelForm):
required_css_class = 'required'
class Meta:
model=Project
fields=('student','topic','languages','duration')

------------------settings.py--------
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}

You might also like