Tutorial by Examples

Django manger is an interface through which the django model queries the database. The objects field used in most django queries is actually the default manager created for us by django (this is only created if we don't define custom managers). Why would we define a custom manager/queryset? To avo...
Model with ForeignKey We will work with these models : from django.db import models class Book(models.Model): name= models.CharField(max_length=50) author = models.ForeignKey(Author) class Author(models.Model): name = models.CharField(max_length=50) Suppose we often (always) access ...
Very often it happens to deal with models which have something like a published field. Such kind of fields are almost always used when retrieving objects, so that you will find yourself to write something like: my_news = News.objects.filter(published=True) too many times. You can use custom mana...

Page 1 of 1