Debian Codegraph @

docs/index.rst

raw ◀ ▶
1 Debian patch touch this file
1 django-polymorphic
2 ==================
3
4 :pypi:`django-polymorphic` builds on top of the standard Django model inheritance.
5 It makes using inherited models easier. When a query is made at the base model,
6 the inherited model classes are returned.
7
8 When we store models that inherit from a ``Project`` model...
9
10 .. code-block:: python
11
12 >>> Project.objects.create(topic="Department Party")
13 >>> ArtProject.objects.create(topic="Painting with Tim", artist="T. Turner")
14 >>> ResearchProject.objects.create(topic="Swallow Aerodynamics", supervisor="Dr. Winter")
15
16 ...and want to retrieve all our projects, the subclassed models are returned!
17
18 .. code-block:: python
19
20 >>> Project.objects.all()
21 [ <Project: id 1, topic "Department Party">,
22 <ArtProject: id 2, topic "Painting with Tim", artist "T. Turner">,
23 <ResearchProject: id 3, topic "Swallow Aerodynamics", supervisor "Dr. Winter"> ]
24
25 Using vanilla Django, we get the base class objects, which is rarely what we wanted:
26
27 .. code-block:: python
28
29 >>> Project.objects.all()
30 [ <Project: id 1, topic "Department Party">,
31 <Project: id 2, topic "Painting with Tim">,
32 <Project: id 3, topic "Swallow Aerodynamics"> ]
33
34 Features
35 --------
36
37 * Full admin integration.
38 * ORM integration:
39
40 - Support for ForeignKey, ManyToManyField, OneToOneField descriptors.
41 - Support for proxy models.
42 - Filtering/ordering of inherited models (``ArtProject___artist``).
43 - Filtering model types: :meth:`~polymorphic.managers.PolymorphicQuerySet.instance_of` and
44 :meth:`~polymorphic.managers.PolymorphicQuerySet.not_instance_of`
45 - Combining querysets of different models (``qs3 = qs1 | qs2``)
46 - Support for custom user-defined managers.
47
48 * Formset support.
49 * Uses the minimum amount of queries needed to fetch the inherited models.
50 * Disabling polymorphic behavior when needed.
51
52
53 Getting started
54 ---------------
55
56 .. toctree::
57 :maxdepth: 2
58
59 quickstart
60 admin
61 performance
62 integrations/index
63
64 Advanced topics
65 ---------------
66
67 .. toctree::
68 :maxdepth: 2
69
70 formsets
71 views
72 migrating
73 managers
74 deletion
75 typing
76 advanced
77 changelog/index
78 api/index
79
80
81 Indices and tables
82 ==================
83
84 * :ref:`genindex`
85 * :ref:`modindex`
86 * :ref:`search`