티스토리 수익 글 보기
Model class reference¶
This document covers features of the Model class.
For more information about models, see the complete list of Model
reference guides.
Attributes¶
DoesNotExist¶
-
exception
Model.DoesNotExist¶ This exception is raised by the ORM when an expected object is not found. For example,
QuerySet.get()will raise it when no object is found for the given lookups.Django provides a
DoesNotExistexception as an attribute of each model class to identify the class of object that could not be found, allowing you to catch exceptions for a particular model class. The exception is a subclass ofdjango.core.exceptions.ObjectDoesNotExist.
MultipleObjectsReturned¶
-
exception
Model.MultipleObjectsReturned¶ This exception is raised by
QuerySet.get()when multiple objects are found for the given lookups.Django provides a
MultipleObjectsReturnedexception as an attribute of each model class to identify the class of object for which multiple objects were found, allowing you to catch exceptions for a particular model class. The exception is a subclass ofdjango.core.exceptions.MultipleObjectsReturned.
objects¶
-
Model.objects¶ Each non-abstract
Modelclass must have aManagerinstance added to it. Django ensures that in your model class you have at least a defaultManagerspecified. If you don’t add your ownManager, Django will add an attributeobjectscontaining defaultManagerinstance. If you add your ownManagerinstance attribute, the default one does not appear. Consider the following example:from django.db import models class Person(models.Model): # Add manager with another name people = models.Manager()
For more details on model managers see Managers and Retrieving objects.
Informazioni aggiuntive
Support Django!
Contenuti
Ottieni aiuto
- FAQ
- Prova la FAQ — contiene risposte a molte domande comuni.
- Indice, Indice modulo, or Tabella dei contenuti
- Comodo quando si cercano delle informazioni specifiche.
- Django Discord Server
- Join the Django Discord Community.
- Official Django Forum
- Join the community on the Django Forum.
- Ticket tracker
- Segnala i bug di Django o della sua documentazione nel nostro tracker di ticket.
Download:
Offline (Django 4.2):
HTML |
PDF |
ePub
Fornito da Read the Docs .