 So what we're going to do next is we are going to start with building the database. So we now have some basic idea of how we can design the business logic, what happens when we hit a URL, how the template is rendered, et cetera. But what we don't have is we don't have any interaction. So we don't have any information that we are providing as input. And we do not have any way to store the data that there's no interaction. There's just plain pages, simple pages that are being rendered. So it is mostly information that is being thrown towards the client, that is you, from the server. So you are getting the return response. You are getting an HTML page. But there is no input from your end. Or there is no data that is being stored from your end. Or there's no form that is being asked from you. So to be able to have some amount of interactivity or some amount of dynamic information that is being stored and then rendered on your page, we first need to design a database. So in order to design a database, let me first go to my command line. So everybody can open their command line. And just make sure that my migrations are also up to date. You don't need to run the command now. I also need to create the SQL user-like documents that are already done, so that I'm at the same page as all of you. Now, so what are we doing next? How it works is I go down into my library manager folder. And if you remember, like Prasame has also mentioned and we had spoken off yesterday, the models.py file is what we need to edit. The models.py file is where you're going to define your database design in a Python effect. So this is a file where you are going to dump all your database designs. How this works is that Django gives you a way of talking to your database using the Python language. You don't have to write raw SQL queries. You don't have to run raw SQL queries on your SQLite 3 or your MySQL database. The Django framework itself gives you something called an ORM, which is an object relational mapper. An object relational mapper is an inbuilt tool or module that allows you to interact with your database. But you don't have to write raw SQL queries. You can actually write very pythonic code. So you can use classes, functions, methods, attributes, variables, et cetera. And you can design a database. You can interact with a database. You can write to the database, do all the create, read, update, delete operations. And all of this you will be doing when, and all the while you're doing this, you'll be using your Python language only. So you can call it an advantage or a disadvantage. If you're using Django, there is, to a very large extent, there is absolutely no need for you to even know how to write SQL queries or how to write raw SQL code. You just can write Python code and you're done. Once you're done, you can, I mean, to a certain extent, you can deal with Python code. Once you're done, I mean, once you go to a point where you are advanced enough, you can then sort of optimize and work with raw SQL queries to sort of optimize certain stuff. But otherwise, you don't even need to know SQL queries in general. So, right. So you are basically going to write Python code and your ORM is equal to internal tool that will basically do the translation of Python code to SQL query internally and then deal with the database. So how do we create? So the first step is creating the database which we did with the migrate command. The second is creating the tables inside it, the tables, the columns, the fields, et cetera. So how do we do that? We are basically going to be writing out a Python class. So if any of you attended the prerecorded sessions with object-oriented programming sessions in Yuc, you will know how to write a class, right? You will have basically the keyword class followed by the class name and then you will write out internal methods or attributes inside it. So what we are doing here is we are going to basically be designing a library management system. So you want to be able to store your member details and you want to be able to store your books that you have in your library, right? So we'll first start by creating the member table. So a table in your SQL database represented by a class in your ORN or your model.py file. So when I say I want a member table, I am defining a member class, right? I will then inherit. So if you studied inheritance in any of those models, you will understand that classes can inherit from internal packages or classes that you already have. So model.model is an internal model parent class that you can inherit from because there are a lot of internal functions and methods that you can use. And the models method also tells Django that this is a very specific kind of a class which is representing a table in your SQL database, right? So we start off with class member which is one of your tables. Now we want to specify the columns in your table. So how do we do that? We define attributes or we define variables of that particular class. And we do that by defining it like a regular variable. So let's say we want a member. A member will be your library member and you want to store details, right? So what sort of details will you store? You'll generally store his name, phone number, maybe some details like address, et cetera. But let's go with name, email, and phone on a very basic level, that is what you will need to store information. So you will have name, let's see. I'm defining a comment, you don't need to copy this but I'm just defining what I want. So I want a name, I want an email and I want a phone attribute, right? So these are the three values, three columns that I need in my member table. Now, how will I, so obviously a column in an SQL table also needs to understand what kind of data it will store. To be able to tell the ORM or to tell the SQL database that we also define the data type that will be storing in that variable. So for example, let's say name. My name will be of type characters. So it will be a type called char field. Char field is an internal attribute or internal method. The internal method, so you don't have to worry about why it is called char field, where it comes from, et cetera. These are feature sets that are provided by Django. Django gives you certain functions or certain factory functions or utility functions. And you can use them to define the kind of data types that you want in your attributes or in your column. So char field is one, the most common one because you want to be able to store strings or characters in a particular column. And you will pass it the argument max length because you usually want to tell how many characters you'll store in that particular column for that particular row. So I for now will store, will allow 255 characters that's a max that you can store. Similarly, email also will use char field for now. And I'll use the same argument here. If you can't see and maximize it a bit. And I'll use phone number. And again, for phone number, I'll use the same field type, right? So we now have the columns defined. I don't need the comments. So I'll just remove the comments, right? So now we have the fields defined. So this is the class definition. The class definition tells you and tells Django what type of table that we are creating. When you're using this class in your code, you will be instantiating a class, right? You have classes or class definitions and you have instances of that class. So every instance of this class will basically be representing one particular row in the database, in the table. So every row will have- I have one question. Yeah. I mean, if you look at the right-hand side of all these three variables, everything is same. Can't we do in one line? Can't we specify them in one line instead of writing them separately? No, because they'll be separate columns, that is one. And secondly, because they have like, I mean, there's probably a way to do it. But you will end up with one line in one row, which will not be very readable, that is one. Secondly, because, and I'll show you how, the migrate command will now use this to be able to generate a table in your database. So you don't want the migrate command doing something funny or something weird. So even though you, I mean, you could maybe say variable name comma variable email comma variable phone equals model care field, but you don't want it to act funny, do something weird, or you don't want to destroy the readability of what you're seeing. So once you have, once your application has many tables and columns, it is easier to just quickly go through your models.py file and look at it, saying that, okay, these are the four columns that I have in the member table. So it is easier to look at, easier to read, easier to understand quickly by looking at it. Instead of shortening it, and you save some lines of code, but you will be destroying the readability and the ease of understanding that you will have when your application grows larger, right? Plus, at least as of now, I can't think of a way to do it in one line for these kind of assignment. You could probably use comma, comma base, comma separated values and assign them to multiple variables that is possible in Python, but you wouldn't want one long line of everything in one line, right? Because it will be difficult one. So separate lines is definitely recommended. That's the standard that any model.py file will have, right? So this is what we have. We have a member table and we have three properties or three columns or three attributes. If you want to sort of, if you not yet typed it or you're finding it difficult to type, I'll leave the GitHub link in the chat again just so that you have a simpler time just looking at the models.py and copying the relevant code. Please don't copy everything. Just copy the parts that I have done. So you can only, you only need to copy from line four to line eight, which is the class member. That should be models, not model. Yes, correct. So that would have thrown an error, right? So it is, I've imported models. So it is a models module that I'm going to use. So it is not model, it is model, correct? From which line to which line we need to copy, sir? The same as the class member. So class, so line four to line seven or eight in the GitHub repository will sort of give you the same content as what I've written now. Once that is done, you save your file in models.py. You go to your command line. Hopefully you don't have your run server running. If you go have it running, you need to close it down and you need to run the command Python, manage.py, make migration, right? This is the command. I'll paste it in chat again. If you remember, we had run this once yesterday, but it didn't give us any output in general because there were no migrations to do or create. I'll tell you what it does. Please paste this command in your terminal, in the correct terminal where your manage.py file is located. Please make sure you are in the same folder as the manage.py file. Please paste this command. Please press enter. And it should give you something of this sort of output. If you saved your models.py file correctly, we'll tell you that there was some migrations for library manager app. There was some file called 0001.initial.py and there was a model that was created for members, right? So what it did was, like I told you last time, there's something called a module, there's a module called ORM, the object relational mapper, and it is handling all the interactions between your Python code in your models.py and your database. We have already created the database, that is the db.sql file that we have, but we now did some changes to the database, right? So we made those changes in the model.py file, but nothing has changed in the db.sql file. In order to make those changes, your Django should understand what those changes are. For it to be able to consume and understand what those changes are, you run this make migrations command. The make migration command tells Django that boss, you need to go look at models.py. There was something that had happened before, but now there are some changes. Please make sure that you're okay again. So please only look at the changed part, not the earlier part. If you find any changes, then please create a migration file, tell your ORM what to do and what to run and what to create, and then stop there, right? So we created something called a migration file. You go back to your spider, you can actually look at your migration file, you can go to the migration folder in your library manager app. You can double click on 001 initial, and you'll see that it has a lot of Python code that is automatically created. What this is doing is, again, using a very object-oriented approach, it is telling Django to basically do a few things for making those changes. Reflect in your db.sql file. It tells it to create the id column, which comes by default, you're not specified it, but the id column is always there by default, that is a primary key. It tells it to create a name column, an email column, and a phone column, and do all of this for a member table, create model with a member name, right? Please do not change anything here because it will mess things up. But this is just to show you that these are the changes that Python has recommended based on our changes in model.py, right? This is internal magic that you don't need to be concerned about unless you're dealing with lots of advanced migration level issues. Can you show that creation of here? Just wait here. Right. In the meantime, the others can, I'll not change the screen, but the others can run a very familiar command that you already run called manage.py migrate. So you have to run Python, space manage.py, space migrate. So what will this do? This will go back to your migration folder. It will check if there are any new migration files that have been created since the last migrate command run, and it will actually go and apply. So what it does is it goes, it check all these internal applications of admin, auth, content types, library manager, sessions, et cetera. It then checks if there was any new file created since the last launch, and then it found that there was one that was created called 0001 initial, and it applied that migration. So what it did, it applied the migrationary changes that you had defined onto your DB-esculide file, right? Until now, the migrations were not applied to your DB file. So you can't just do make migrations and forget. You have to also run the migrate command. You'll be able to see the changes in your DB. If you're only done make migration, no changes would have shown up in your... Yeah, yeah, that is happening, yeah. Okay. So in that case, what we need to do? You need to run your make migration command first. You need to then run your migrate command second. Python manager, you are migrating. So I'll switch back to the chat, and I'll wait for everyone to make sure and tell me that everything has happened, run, and everything is working fine. So working fine in the sense that you've not got something that looks red, or says error, or says exception, cool. So once you've done this, you should be able to see, so now where will you see these changes? So there are a couple of ways to see these changes. One, the easiest way is run your server, because this is the most user-friendly way. You can run your server using the run server command. Once you run your server using the run server command, you can go, you can click on your browser. You know which website to visit, that is localhost 8000. Open your admin interface like you did in the earlier session. It is not fitting the 001 init file. Right, so I'll come back to you. Can you share your screen please, quickly? Yeah, yeah, I'm sharing. You are screen- Can you run both the commands? Your screen is active, sir. Yeah, have you run both the commands? Yeah, I run both the commands. On make migration, did it say that the 001 file was created? No, I will show you. Can you open your model.py file, sir? Yes, I am opening. I will show this one. No, I can see that you have an output on the top saying no changes detected. Yeah, yeah. You can go to your model.py file. See, sir, model.py. Can you go to spider? Again, this seems to be a case where your model is in some other folder and you are editing it in some other folder. Yeah, probably. Can you please make sure that you're editing the right file? I will show you. Seems to have an empty file and you just pasted it and you don't have your imports as well. The model's file is here. Library model. Correct, it is the wrong place. You need to go into library manager and then open the model.py file that is already located there. Yeah, this one, yes. Correct, so please paste everything that you added into your original file into that model.py. Do not remove anything that is already there. Please run both those commands and everything should work. Right? Please do not replace everything. Please add it to the, what? Yeah, that I have done. Yeah, thank you. Just save it. This should fix it for you. This file has to be removed. Your original, the original models that you had on your top folder that you don't need, you can delete it. Yeah, I will. So generally 99% of the time you don't need to create files. There are almost all the files are created for you. There will be some specific files that need to be created like templates, et cetera. But the major files are already created. Anyone else having any issues? Everything you can find for most of them. So we'll go back to what we were doing before. So I forgot one step that I needed to tell you about which is editing the admin.py file. Admin.py file is a file that contains any customizations to your admin interface. Your admin interface was the interface that you logged into using your username and password. Right? So in your admin interface, you can open your admin.py file which is inside library manager app. It already exists. Please open your admin.py files in the meantime. Right? Now, what you need to do is you need to import your models and then one second. You need to import your model. So from dot model, so your existing model, you will import the book model. Sorry, the member model. You don't have the book model yet. And the member model will be registered on your admin interface. How do you do that? You use the admin tool which is already imported for you. You tell it to register the model that I'm importing from my custom app. So I'll give it the model name. I use the internal methods admin.side.register. And this should be enough. Right? So this will sort of tell Django that boss, I want to be able to see the member model and all the rows, all the data that is stored in the member model on my admin interface. Once you save this, you can go back to your terminal. You know what to do. You need to run your server. Once you run your server, you can go back to your browser. Your browser should have your admin interface. Hit your admin interface, log in if you have to log in. My session was already active, so it allowed me to continue. And it will show me the members model showing up here in the interface. So it will show the app name, library underscore manager. It will show me the members model here. Hopefully everyone has reached here. I'll just click on it. I'll show you the interface. In the meantime, you can make sure that you can see the interface and you can interact. This is sort of a very simple way to add, delete and update your database data information. So one of the major advantages of having Django is that you can build a very simple data entry application without even having to write much code. I've added one model, one admin interface change, and I don't even have to add views.py. My admin interface automatically gives me an interface to edit and add and delete information. How does it do that? It gives me this pre-populated template and interface. I can add a member here. I can tell that my member name is Aniket or Ankit. I can add my email, Ankit at Ankit.com and I can add my phone number which is plus 919894446767, right? And I can save it. Once I save it, it shows up as a first member object or the first member row in my database, right? So you can sort of play around with this if you want to, you can add multiple things. The only thing that remains is sometimes as a super user, when I'm looking at my database or looking at what I need to do, what sort of members I've signed up, I want to be able to see the proper representation of my object. So what is this? This member object is the instance of my member class. Like I mentioned before, every row in your database is a instance of your member class or your model class, right? If I want for any class in Python, if I want to change how the class is represented on the command line or anywhere, I can use a special internal private restricted method called str and we'll change that now to be able to see a more better way of looking at this object or this instance. I hope everyone is up till here. They're okay with the setup. You need to show us the admin pipe file. Okay, you don't have to see the admin.py file. The repository that I've given you contains the admin.py file if you look for it in GitHub. But if you want to see the admin.py file, I can show it to you as well. But otherwise, does anybody have any issues? Remember one is done, correct? That is the only one that you need to do for now. So we are registered in admin. We have already created one model. What we need to do is we need to go back to model.py because you want to change how the model class is being represented in the admin file. In order to do that, what you need to do is you need to define a method called a restricted or a private method called underscore underscore str underscore underscore followed by the self argument for that class. And inside that, you will return the way that you want to display the object. So for me, when I look at the object, I want to quickly understand who this member is. So what I can do is I can return the name of that member. So self.name is basically the object-oriented way of referring to the class attribute here, which is the name property of the member method or the member class. So self.name will give me this name, the value stored in this name variable here, and it will show up there on the admin as well, or even when you're using it in your code, in your command line, et cetera, it will show it as a fancy name. Otherwise, it is difficult to understand which object it is, who it belongs to, et cetera. I've made this change. Again, this change will also be visible in your GitHub repository that is already sent. So you don't have to wait for me. You can add this one method, which is the double underscore str double underscore. That is a double underscore there, right? And once I've saved this, I can go back to my admin interface. If you refresh it, it will show me that the name is uncid, right? So this now changed. Why? Because my method was added and the method is giving you a very fancy way of rendering the name of that particular object. So you can try adding few more members if you want to. I'll just quickly show you. This is the sort of interface to sort of edit your database row. If it's a care field, then you are given a text box. If there's a number field, then there'll be certain validation that will be applied. So apart from care field, you can have email field, you can have URL field, you can have text field, which is a larger text box. And we'll see that in the next model. You can have other model attribute types or data types. And what they do is, when you're entering data from your code or from the admin, the data is automatically validated. So if I go here, if I were to go to a character level that is beyond 255, then it will sort of throw me error saying that, you know, you can't enter more than 255 character. So those validations are what Django already is giving you using those care field method, right? I can also delete the rows from here quickly. If there are more than one row, I can sort and delete multiple entries, et cetera. So that is also possible from this interface. So this is a very quick and dirty default interface that you can use for data entry application. So if you have a very simple application that just needs data entry, Django is a good application to web frame of use, right? Yeah, so let's go back to our models and see if we can add one more model. So we have a member model now. We want to be able to store books, right? So we want to be able to create a book model. So I'll quickly create one. I'll just move back to my file as well. Sir, one show. So I've already sent the link to the GitHub repository. Can you please scroll up in the chat and have a look at the admin.pu I find there, please? In the meantime, I can just make sure that I'm typing out the correct model. Please scroll up in the chat. You should be able to find the GitHub repository that I sent. If you can't find it, please let me know and I'll send it again, right? So now I have a class book. I can add, what can I add? I can add the title. So title also, I will keep it as model.carefield. Again, I just keep it at 255 because I want it as long as possible. I quickly copy paste these tools because I don't want to spend time typing them. So what I want for the book is I want a title. I want to be able to store who is the author. So I want to store the author names. I want to store the ISBN number, which is the unique identifier for every book that is ever published. And I want to be able to store the genre or the category of the book. Last but not the least, I will show you another field type which is the text field. So I want a description field to store a larger piece of text that can store more information. So I want to be able to type out the description of the book. And like we did last time, I will have a string method here. It will have a self argument. And here also, I will return the title of the book so that I can quickly understand which book the object or the database row is talking about. And I will save it. I will circulate the GitHub link again so that if you don't want to type all of this, you can quickly just copy. It's already shared on the chat. Yeah, I'll just do it again. So my link directly goes to model.py. I mean, it's the same repository. It's fine. You just need to copy the part that talks about the book model. So the book model is about from where is it from? From line number 13 to line number 21. That is what I typed out exactly right now in front of you. Save the model.py now. And this time, I will not do it. I'll wait for you to do it for me. You need to do the migration and make sure that the migration is applied on your database. So now I'll just show you as a sample. I've saved my model. Now when I go back to, let's say, my website or my admin, it still does not show me the book model that I've added. So we need to do three things. You need to be able to do the make migration. You need to migrate and you need to update your admin.py file. So I'll wait for all of you to do that. And you will now tell me what I need to change in admin.py so that it will show up here. Before you do any changes to admin.py, first run the make migration command. Second run the migration command. Then change the admin.py file. And then please let me know what I need to do so that I can get the same output as you. It shouldn't take more than five minutes. So show the admin for models file. The models file, I've sent a link in the chat. You can have a look at that. You don't need to wait for me. It's on line number 13 in the link that I've shared in the chat. Basically all of the class book. All of class book. Right? So once you're done with the migration and the admin registration, please let me know and please tell me what I need to do. What code I need to type. You can even share your screen if you're done. Sir, how to register? Nothing is showing when we click it. Where are you clicking? Sorry? This Github. So the link that I send is not opening up? No, it is opening but it's not active link basically for registration purpose. No, no, you misunderstand what I'm trying to tell you. That link that I sent you is not for registration. It is for models.py content. So you're asking me to show the models.py instead. Why don't you have a look at that link? It has the models.py content in full. You just have to copy paste the class book out of that content. Yes, yes, yes. Hello, sir. Yes, I added the book successfully. Cool, okay. So somebody told me from models import book and then admin.site.register. So where do I do this? Correct, okay. In admin.py, I basically import I import the book. So you're already importing from .model so you don't need to add a new line. You can just say comma and I want another I want to import one more class which is member comma book. You don't need to have multiple lines for every import. You can just add it in the same line because you're importing it from the same place. Your source is the same. So you can put it in one line. And like we registered member you have to register book. So once you've registered you should be able to see it in your admin. Please just add a couple of books and just fill in some data. I'll also do the same. I'll go to my admin and I'll see if things are showing up. Correct, so books is also showing up. So books is an interface for me to have something but like I said I didn't do the migration. So you just told me the admin.py I didn't do the migration. So it started showing this error at me that we don't see the table. So how should we show you what is happening? So this is the error that will show up if you don't do a migration, the proper migration. So I will first run make migration because I created a new model so I need a new migration to tell my migrate command what to do and then I will run migrate which is my actual application of that migration. This is done. Hopefully it should work. So I need to run my server and yes, so it is showing up. So this is the books interface. Right now there are no books so I'll add a book and in the add interface you'll see that there are care field interfaces. Lord of the Rings is one of my favorite books. I'll add that. Author name is GRR Tolkien. GRR for short. IHB number is about 13 or 15 digits long so I'll just add something that looks close to a IHB number. So I think I added something large. Genre is let's say fantasy and this is a description. The admin interface automatically detected that the description is a text field and not a care field but gave me a larger text box using JavaScript to sort of type larger amounts of text with no limitations. So this is a fantasy novel about hobbies. So I'll save that. What else? I'll add one more book and some database to work with. What is that other popular one? Game of Thrones and I forget the author name so I'll just call him that guy and IHB number again is some random number. Genre again is fantasy. Description is randomly long novel series and save that and now I have two books. We can also enter some data so that we have some data to play around with. Right, so we now have books and we now have members. Sir, I have some problem in this model file. Okay. One server is not also able to run it. Can you place the error in the chat? Okay, I will put the error in the chat. Right, everyone else have they been able to register their book model, get the migrations correctly and be able to enter the data? Invalid syntax. So sir you either have something wrong with your syntax which is that there is no space between depth and double understood. So we need to put a space there. Yeah, yeah, yeah. Sir, actually my laptop is not showing a library manager is not showing can you show me that initial.py Which one? What is not showing on your laptop? The library number changes. It's not showing. You have to show it. When you visit this interface, can you see members or books or whatever? No sir, it's not showing a library manager. Option is not showing if I run that Okay, so it's not showing a library manager. So then your admin.py is supposed to have some things to change. So you need to add these three lines. Okay sir. .models, import, member, book, admin.sign.register member, admin.sign.register book and any more models that you need. Moving on. Now what we are supposed to do is we already know how to register your models, how to migrate them, how to see them, but generally what happens is nobody wants to look at the boring admin interface. You generally want more features, you want an interface that looks more fancier, you want more flexibility in defining your templates, changing your HTML, making it look better or different from what it is looking right now. You may not want the Django administration sort of title to show up here. So you would want to design your own template. So obviously Prathamesh earlier session has already showed us what we need to do. We already have one template as well. And we have a URL as well. But let's go back and change it a little bit so that it shows us all the books. So now we have some data in our database. We have some business logic in place. We want to be able to see the data that is stored and not just the default data that we entered before in the function. So what Prathamesh had done was just to show you an example. He had hard coded stuff in the views.py so that he could show you how the templating and how the views logic work. But we don't want this hard coded stuff. We want to be able to see what has been added. So tomorrow somebody if my super user or my librarian came in, added new books into the interface. I don't want to keep seeing the biology and the Sylab book. I want to be able to see what new books are added and if any changes happen the changes should also reflect on that template. So for that to happen you need to be able to do few things. You need to be able to run a query using your ORM logic. You need to run a query and get all the books from your database. And then once you've got all the books from your database you need to be able to pass them to your contacts and to your templates. And in your templates then it needs to be the correct ginger templating language to be able to show them. So we've done parts of this we've now connected all together and I'll show you how to run a query. Is everybody done up till the stage? I hope that they're not nobody's falling behind. Sir what you have added in views I mean just one or two minutes before? I didn't add anything. I didn't make any changes. So if you're getting an operational error most probably you didn't do your migrations correctly. Can you do make migrations and then migrate? Sir I have done. I got it. So now the next step is changing the views and running a query. So what we'll do is we'll run the query first and then make the changes to put a little later. So you need to now add a line to make the query. So how do you make a query? You first import the the book model that you have created. How do you do that? From.models import book. You can also import member because you've already created you might as well import it here. Right? And you can write a query by using specific ORM based methods and attributes. So to be able to get all the books for now let's keep it simple and get all the books while typing a variable called all books to store all the queried books that I get. All books equals book.objects.all and open bracket So what does this do? It takes the book object. It takes the book class which table it wants to query. .objects is a utility method. .objects.all tells that I want to run a query that says select star from book. That is a query that you run. So this is equivalent to select star from table name. What is the table name? That is book or small book whatever. Right? It is not that good because I am usually a dango developer but this is roughly what the SQL query will look like if it was translated into SQL. So it gets you it gets you all the books from the book table. And because this is Python we can basically deal with them like we deal with standard data types and data structures. So we can store them in a variable. Now what will we do? We can then pass all the books to the template using the context. We will use the same variable called all books. We can call it any other variable but we will use the same one to avoid more confusion. And what I have done is I have passed in the variable. So the context is always a Python dictionary so you cannot change that but you can add any data structure within it. So you can give it a key and the value can be a list, it can be integer anything. In this case I wanted to show all the books so I am passing it all books variables which I have already created here. Right? And the context is already passed to a books.sqml. Correct? So have these changes been made and are you done with these changes? Save the file, make sure that you have saved it. Please let me know once you are done with this. I will minimize it. Sorry I am stuck. So can you please check your models.py. Does your models.py file have a book model? If it has a book model then it can be imported. It has sir but it is not Smith we are not supposed to do any migration. If I said migrate I am sorry it must be an error. There is no migration required after editing the blue salt p1. Jayan can you can you share your screen? Sir I can serve once. Sorry someone was saying something else. Sir after saving the file so it will run the server again nothing else is you can migrate. Yes you can run the server again but in general please wait and I will tell you what to do. Sir can I do sir? You can share your screen now. Correct so your book is being imported here right? Does it work or not work? Can you show me models? Models. Remember so you not created the book folder the book the book class yet. Please create the book class please look at the GitHub repository it has the book class. Please copy that book class here and you should have the book class ready. Once you have the book class ready you can import it. If you remember I told you 2 minutes ago that you don't have book in your models.py which is why it is showing up as an error right? Yes I will tell you what to edit I just need to make sure that everybody is on the same page is everybody done till this point have they edited the views.py file? Okay cool so going back to the views.py file is done you now need to go to the template that you created so you have templates you have library manager inside template then you have books.html which is already created please double click on that so what you need to do here is you already have a context variable for all books which contains a list so consider all books to be a list of all the database entries that you have now you want to be able to display all the books in one sort of in one one after the other so if you had a list of values and you wanted to print those values in Python how would you write them what would you what kind of code would you write to print all the elements of a list one after the other can someone tell me loudly because I am not looking under chat I don't know what you are typing we can use the root you can use a loop loop yes what kind of loop for loop okay so that is the correct way to go about if you have multiple multiple elements to show the simplest and the most you know basic way to do it would be run a for loop on that list on that itrable and display all the elements inside so we will do the same thing I will just quickly paste the templating language reference of the Django documentation you don't need to look at it now I am just placing it for reference right so we have the books title we have the ordered list and we have each element right but we want to run the for loop and we want to display one element per for loop iteration right so how will we write that in Django templating language you can actually write you can write syntax that is very similar to python code so you will for variables you saw that we use double braces for computational statements we will use curly braces percentage and we will write some limited amount of code in these kind of syntax for I will just use the variable my book so that nobody confused for my book in all books because the context variable is called all books so we are using it in the for loop the for loop like you see is very similar to the python for loop right so the templating language is very similar in Django is very similar now I want to be able to show just one book for every iteration so I will remove this second li option and I will end the for loop so this is something that is not the same as python so I need an end for because my templating language needs to understand where the where the syntax started and where it ended and where html is starting where html is ending inside this the variable my book because in the for loop I declared the variable my book so I am using the variable my book what this will do is inside an ordered list tag it will run a for loop and it will create multiple li element for every book element in the all books list and it will show up all the book without having to write much more html code you can display everything in one book so I will save this so please save this please write this out and I will wait for sometime in case you are done typing you can run your server you can open slash books so localhost 8000 slash books in your browser folks are already done with these changes everything should work fine you should save all your changes in book.html and news.py you should run your run server command you should be able to see your browser and open the slash books url because you remember that the slash books url is the only one that you add correct so like I said it will show all the books in one book if you want to sort of see see why we did this you can go back to your admin interface you can add some more books like 4-5 more books or 2 more books and they will also then show up on your terminal you are going to do this one by one obviously so it will look like you are doing this one after the other but if I were looking at your page and you added something in the background in the database and if I hit refresh from my browser it will immediately update it and I will be able to see the updates that is why you would want a dynamic database driven application in the first place please let me know if you are done copying it from the screen I can sort of move back to chat and sort of the link that I added for the Django documentation gives you more details about the templating language it will give you like you know it will give you more syntax related stuff you can do a lot more things you can use variables you can assign value to variables you can access elements of a list you can filter values you can do some string manipulation in template a lot of stuff can be done in the template because the templating language is pretty mature generally though it is good practice to only use the template for rendering the data and not manipulating the data because your logic should be located in your views and your template should only be doing the rendering part okay can I share the screen once can I share the screen once what is the issue when I am going to the book URL that only 1 to 3 point number is coming name of the books are not coming 1 to 3 point number is coming but name is not coming okay let's see what it shows up for me or it will be like so it is showing up here in your case can you share your screen I will stop sharing mine just one second can you share your screen can you show me your views.ky no sorry can you show me your template html template let's go one by one you have li for booking on my old book 1 you are using a variable called book 1 but your variable in for loop is my book now because book 1 is a variable that has not been declared before and the template does not know what the my book 1 variable is so it displayed a blank value you need to type in my book right so sir I did the same thing and it showed book object but when I change it to my book.title it shows me correct title correct so there is a reason for that in views when we are running a query the result of this query is basically the instances of the book class you have an object you have a list of objects in all books your book each element of book in your all books is an an instance of the book model so the book model every instance will have the title value author name value etc so you are passing all of that to your template and your templates can access elements of the book you can say book.title, book.author name book.isb and number etc and you can also access that what you have not done and why you had to do .title was you didn't add your str here which is why it shows up as book object book object 1, book object 2, book object 3 book object 4 you can do it now if you want to it is not necessary just fine what you have done is also very commonly used you can say my book .title so in fact I will show you something that works the same way so I will say book.title and I will also want to see the author my book.author and I will encase it in double braces and save it you don't have to do this I am just showing it as an exercise just to show you how it is not visible so what I did was I already had my book here I added the .title attribute I added a colon and I added another variable for my book.author you don't need to do these changes you can see that I am showing you just to show you how it changes so I also want to see the author along with the book I don't want the book name only in that case I made these changes save them and because it is just an HTML change I don't need to do anything fancy and I click here and it gives me nothing why does it give me nothing because my author name is not shown author name is the field name sorry so it will give me the author name here so you can do all this kind of stuff you can manipulate some information and presentation in your template itself and you can display it in a fashion that suits your design this is a very simple template you can obviously do a lot more stuff here you can add bootstrap css you can make it more fancy you can give it a header a footer but we are not doing it because of time constraint so I will give you a brief overview of what is happening and this should tie the whole story together so let's assume that my web application my dango application is stored on a remote server it is stored somewhere in the cloud on a computer like this computer but somewhere with a public IP address in some data center so what happens to websites that are stored on the internet they have an IP address the IP address is a public IP address but because you don't want to remember and it is very hard to remember IP addresses the folks who created the internet came up with a very you know fancy way to deal with it they basically tied a name with an IP address with a domain name so your facebook.com is basically something which has an IP address in the back but because you don't want to remember the IP address you can type in the name and your computer will do the translation of that name to the IP address so in my case my website is localhost which is basically just pointing to the IP address of my computer server let's assume that this is a website name in the top level domain now when I access flash books what happens is I am accessing a particular URL which I know exists this request is sent to my remote server which is in the cloud the remote server has the web application all the fancy tools running on the server and it has the Django app running so basically something is happening on my remote server right when I hit this particular URL my browser sends an sttp request the sttp request contains the URL that I want and it contains more information if that more information is included in this case there is no more information this is just a plain URL and I am requesting for information from the server so there is no additional information now when this request reaches my server here what does my Django web server do it received a request right when it received a request these are how the received request look like so it got a request saying it is telling me I got a request for books via sttp and I am now going to send it back to send back a response so it gets a request like this the Django application then understands that there is always going to be a URL so the URL needs to be checked so it goes to the url.py where is my url.py somewhere here in the library management right right here so it goes here now it will have a list of all the patterns that exist for this particular application it will check does the incoming URL request have admin in it no does it have books in it yes so which view should I trigger if I am supposed to do some computation which view should I go to so if I get a request for this URL I should be triggering the books function in my views file so now it goes to the views file it works for the method books it runs all the code within books and when you say return render it creates a template out of the template that you have given here in HTML it adds all the context there there is a templating engine that also runs in the background it packages all the data that it got in the context it sticks it into the template file so it is like creating a you have a page you are going to stick all the data into the variables in the HTML template and once the template is created it will create a response object the response object is created in a certain fashion that conforms to the HTTP protocol and the response is then sent back by Django and it is thrown back to your browser because it knows that the request comes from your browser it goes through all the internet connections and comes to your browser back when it is sending the response back the response contains the complete HTML that you have in books along with the context properly packaged in between what happens you are also doing some database query that is something that you added to the views.py so here when you are running the ORM code the ORM engine comes into play it sort of computes what query is being run it goes to the database which is all the information that is necessary and comes back so this is how the database comes into the picture so this is your full cycle of a request and a response that comes back and this is how Django sort of evaluates things together and stitches all the files together and the reason why we have been filling different different files together is because this is the flow that happens you get a request your url.py is checked your views.py function is triggered your models.py queries are run on your models your templating engine creates a template based out of the template that you have stored in your template folder and then a response is created out of all this and your browser renders the response that is how your whole web application works and that is why it is designed this way