Hello, and welcome to our lecture on owned rows in Django. So what do I mean by an owned row? Well, up to now, every CRUD application that you've written, you got a table, or a model, or two, maybe they're connected, but basically if you log in you can edit every row. So if you do a list, you see an update and delete button on every row. Real applications don't work that way. If you're building a classified add system, some ads belong to you and some ads belong to other people, you can see them all, but you can't edit them all. So we have to decide when to put the edit and delete buttons up and only do those for the owner. We've got to make it so you can't sneak in and edit and delete other people's stuff. So we have to protect these rows from being edited or deleted by anybody but the owner, but anybody can see them. So that's why I call them owned rows. If there's a row that you own, you will see an edit or delete button. If there's a row you don't own, you'll see the row, and the data, and you'll be able to read it and view it, and that's it. So if we go back to how we were working in our CRUD application, we were making heavy uses of these generic views, the generic ListView. So when we're all said and done, after a whole bunch of machinations, you ended up with a very simple view. You ended up with a horse ListView that extended generic ListView. Generic ListView is provided to us by Django and the only thing we had to do was take this code, which is several thousand lines of code, and inform it as to which model we want it to be, and then we make another view. So we make the horse ListView by extending generic ListView and informing that ListView that we want to do this in the model with horses. From that point on, all kinds of convention happens. So we know things like the variable will be named horse_list. It'll be a list of model objects that we retrieved from the database. So we know how that works. It makes things really simple, not a lot of repetition, every view looks the same. You probably have done a cats, or dogs, or all those couple of different things, and they all look very much the same and if you get good at it, you should be able to make these changes very rapidly. So if we look at how this is working from an object-oriented perspective, we are making a new class called gview.views.HorseListView. We are extending our parent class, the generic ListView, and we're adding our own little special source by saying, one class variable model equals horse. So that's what's going on here. Now, in this owner view we're going to do something quite similar, and that is, when we're going to have an article, and this is all from the DJ4E samples myarts example, we're going to extend OwnerListView. Now, soon we will look inside OwnerListView and we'll see that OwnerListView is extending generic ListView. Where this model equals article is informing OwnerListView, the difference is this is our code. That belongs to us. In the last part, we will show you everything that you have to do to build one of these things. So we're taking the ListView, which has almost everything we want and we're going to add one feature to it. Then we're going to extend the ListView and create a new view called OwnerListView, or you might call it ListView for owned rows. At that point you're good. This class OwnerListView, which we'll see in a second, has everything you need to deal with rows that are owned. For example, we're going to have a owner column. So every article is going to have an owner, and if that's equal to the current logged in user, then we're going to show these little edit and delete buttons. But if the article owner, the owner value inside the article object or the model, if that owner is not equal to current user we don't show it. Now, not showing a link does not mean you've protected it from editing, I will show you later how that protection from editing happens. But this is such a common problem that we want to just be able to, in a sense say, "Look, here's a ListView with this special owner column in it and we want to maintain the owner column, we don't want to have to write hundreds of lines of code in every view that we want to have this owner column, so we just use object oriented techniques to accomplish this. So we're going to use inheritance, and we talked about it and we'll talk about it again. Inheritance is the idea that you have a class, you're going to make another class that inherits all that parent class, and then extends it, adds a little bit of stuff to it. It's another form of, don't repeat yourself. Do something once in a parent class, you make the parent class sometimes quite generic, then you make a child class that extends the parent class, and then we use the child class or we could call them subclasses or child classes. There's a whole bunch of different terminology and it's all pretty much equivalent. Subclasses are more specialized versions of a class. They inherit attributes and methods from their parent classes and can introduce their own. Again, basic object-oriented programming. So up next we're going to talk a little bit about how it is that we can pick in to one of these generic views and add our own special source for it.