The document outlines the development of a Django application for student registration and course enrollment, including the creation of models for students and courses. It discusses the Django admin interface, its customization, and the use of Django ModelForms and generic views to streamline CRUD operations. Additionally, it covers generating CSV and PDF files from the application, emphasizing the importance of non-HTML content handling in Django views.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views23 pages
Day4
The document outlines the development of a Django application for student registration and course enrollment, including the creation of models for students and courses. It discusses the Django admin interface, its customization, and the use of Django ModelForms and generic views to streamline CRUD operations. Additionally, it covers generating CSV and PDF files from the application, emphasizing the importance of non-HTML content handling in Django views.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23
Full Stack Development with Django
Develop a Django app that
performs student registration to a course. It should also display list of students registered for any selected course. Create students and course as models with enrolment as ManyToMany field.
Dept. of AIML, JNNCE
Full Stack Development with Django
Django Admin Interface
When you start a project with Django it also provides a default admin interface that can be used to perform create, read, update, and delete operations on the model directly. It reads a set of data that explains and gives information about data from the model. Provides an instant interface where the user can adjust the contents of the application. This is an in-built module designed to Dept. of AIML, JNNCE Full Stack Development with Django
Dept. of AIML, JNNCE
Full Stack Development with Django
Need of Django Admin Interface
Automatically build CRUD for models
Lot of repetitive tasks is avoided Can be customized It is an authentication based dashboard which restricts to privileged administrators Has powerful features of search and filter Dept. of AIML, JNNCE Full Stack Development with Django
For student and course models
created in Lab experiment for Module2, register admin interfaces, perform migrations and illustrate data entry through admin python forms. manage.py createsuperuser
Dept. of AIML, JNNCE
Full Stack Development with Django
Customization of Django Admin Interface
Change site title, site header and
index title (urls.py) Change the path of the admin (urls.py) Making fields optional (models.py blank=True, null=True setting). Needs remigration. Display selected fields in customized Dept. of AIML, JNNCE Full Stack Development with Django Changes in admin.py @admin.register(Student) class StudentAdmin(admin.ModelAdmin): list_display = ('sname', 'usn', 'sem') ordering = ('sname',) search_fields = ('sname', 'branch')
Demonstration of users and groups in
Django admin interface
Dept. of AIML, JNNCE
Full Stack Development with Django
Dept. of AIML, JNNCE
Full Stack Development with Django
Django Model Form features
Django ModelForm is a class that is used to directly convert a model into a Django form. If you’re building a database- driven app, chances are you’ll have forms that map closely to Django models DRY philosophy ModelForm offers a lot of methods and features which automate the entire process and Dept. of AIML, JNNCE help remove code redundancy. Full Stack Development with Django
Develop a Model form for
student that contains his topic chosen for project, languages used and duration with a model called project.
Dept. of AIML, JNNCE
Full Stack Development with Django
Dept. of AIML, JNNCE
Full Stack Development with Django
Need of Django Generic Views
Writing web applications can be monotonous, because we repeat certain patterns again and again. Django tries to take away some of that monotony at the model, template and view level. Django’s generic views were developed to ease that pain by facilitating writing quickly common views of data without having to write too much code. Eg: displaying a list of objects, and displays a list of any object. Dept. of AIML, JNNCE Full Stack Development with Django
Capabilities of Django Generic Views
Perform common “simple” tasks: redirect to a different page and render a given template. Display list and detail pages for a single object. Present date-based objects in year/month/day archive pages, associated detail, and “latest” pages. Allow users to create, update, and delete objects—with or without authorization. Dept. of AIML, JNNCE Full Stack Development with Django
For students enrolment
developed in Module 2, create a generic class view which displays list of students and detailview that displays student details for any selected student in the list
Dept. of AIML, JNNCE
Full Stack Development with Django Useful Django Generic Views
List Detail View View
Create Updat Delete
View eView View
Dept. of AIML, JNNCE
Full Stack Development with Django
Interacting with Non-HTML content
Dept. of AIML, JNNCE
Full Stack Development with Django
views with Non-HTML content
Normally a Django view receives HttpRequest request and returns HttpResponse By using mime-type in the constructor of HttpResponse, one can return Non-HTML content One can return image, XML, CSV, PDF etc by including appropriate mime type
Dept. of AIML, JNNCE
Full Stack Development with Django
Dept. of AIML, JNNCE
Full Stack Development with Django
CSV is a simple data format usually
used by spreadsheet software. It’s basically a series of table rows, with each cell in the row separated by a comma Program to illustrate returning a constructed csv file to browser Dept. of AIML, JNNCE Full Stack Development with Django
Develop example Django app that
performs CSV and PDF generation for any models created in previous laboratory component
Dept. of AIML, JNNCE
Full Stack Development with Django Portable Document Format (PDF) is a format developed by Adobe that’s used to represent printable documents. It is complete with pixel- perfect formatting, embedded fonts, and 2D vector graphics. It is a printable document also.
Dept. of AIML, JNNCE
Full Stack Development with Django
pip install reportlab
Dept. of AIML, JNNCE Full Stack Development with Django
Develop example Django app that
performs CSV and PDF generation for any models created in previous laboratory component