Module todo.models

Expand source code
# MIT License

# Copyright © 2024 Akarsh Reddy Eathamukkala

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the “Software”), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to
# do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

from django.db import models
from django.contrib.auth.models import User


class List(models.Model):
    title_text = models.CharField(max_length=100)
    created_on = models.DateTimeField()
    updated_on = models.DateTimeField()
    list_tag = models.CharField(max_length=50, default='none')
    user_id = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)
    is_shared = models.BooleanField(default=False)

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.title_text


class ListTags(models.Model):
    user_id = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)
    tag_name = models.CharField(max_length=50, null=True, blank=True)
    created_on = models.DateTimeField()

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.tag_name


class ListItem(models.Model):
    # the name of a list item
    item_name = models.CharField(max_length=50, null=True, blank=True)
    # the text note of a list item
    item_text = models.CharField(max_length=100)
    is_done = models.BooleanField(default=False)
    created_on = models.DateTimeField()
    list = models.ForeignKey(List, on_delete=models.CASCADE)
    finished_on = models.DateTimeField()
    due_date = models.DateField()
    tag_color = models.CharField(max_length=10)

    objects = models.Manager()

    def __str__(self):
        return "%s: %s" % (str(self.item_text), self.is_done)


class Template(models.Model):
    title_text = models.CharField(max_length=100)
    created_on = models.DateTimeField()
    updated_on = models.DateTimeField()
    user_id = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.title_text


class TemplateItem(models.Model):
    item_text = models.CharField(max_length=100)
    created_on = models.DateTimeField()
    template = models.ForeignKey(Template, on_delete=models.CASCADE)
    finished_on = models.DateTimeField()
    due_date = models.DateField()
    tag_color = models.CharField(max_length=10)

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.item_text


class SharedUsers(models.Model):
    list_id = models.ForeignKey(List, on_delete=models.CASCADE)
    shared_user = models.CharField(max_length=200)

    objects = models.Manager()

    def __str__(self):
        return "%s" % str(self.list_id)


class SharedList(models.Model):
    user = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)
    shared_list_id = models.CharField(max_length=200)

    objects = models.Manager()

    def __str__(self):
        return "%s" % str(self.user)

Classes

class List (*args, **kwargs)

List(id, title_text, created_on, updated_on, list_tag, user_id, is_shared)

Expand source code
class List(models.Model):
    title_text = models.CharField(max_length=100)
    created_on = models.DateTimeField()
    updated_on = models.DateTimeField()
    list_tag = models.CharField(max_length=50, default='none')
    user_id = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)
    is_shared = models.BooleanField(default=False)

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.title_text

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var created_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var is_shared

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var list_tag

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var listitem_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related objects through the reverse relation.

    With the example above, when getting ``parent.children``:

    - ``self`` is the descriptor managing the ``children`` attribute
    - ``instance`` is the ``parent`` instance
    - ``cls`` is the ``Parent`` class (unused)
    """
    if instance is None:
        return self
    key = self.related_manager_cache_key
    instance_cache = instance._state.related_managers_cache
    if key not in instance_cache:
        instance_cache[key] = self.related_manager_cls(instance)
    return instance_cache[key]
var sharedusers_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related objects through the reverse relation.

    With the example above, when getting ``parent.children``:

    - ``self`` is the descriptor managing the ``children`` attribute
    - ``instance`` is the ``parent`` instance
    - ``cls`` is the ``Parent`` class (unused)
    """
    if instance is None:
        return self
    key = self.related_manager_cache_key
    instance_cache = instance._state.related_managers_cache
    if key not in instance_cache:
        instance_cache[key] = self.related_manager_cls(instance)
    return instance_cache[key]
var title_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var updated_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var user_id

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var user_id_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]

Methods

def get_next_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_next_by_updated_on(self, *, field=<django.db.models.fields.DateTimeField: updated_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_updated_on(self, *, field=<django.db.models.fields.DateTimeField: updated_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
class ListItem (*args, **kwargs)

ListItem(id, item_name, item_text, is_done, created_on, list, finished_on, due_date, tag_color)

Expand source code
class ListItem(models.Model):
    # the name of a list item
    item_name = models.CharField(max_length=50, null=True, blank=True)
    # the text note of a list item
    item_text = models.CharField(max_length=100)
    is_done = models.BooleanField(default=False)
    created_on = models.DateTimeField()
    list = models.ForeignKey(List, on_delete=models.CASCADE)
    finished_on = models.DateTimeField()
    due_date = models.DateField()
    tag_color = models.CharField(max_length=10)

    objects = models.Manager()

    def __str__(self):
        return "%s: %s" % (str(self.item_text), self.is_done)

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var created_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var due_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var finished_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var is_done

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var item_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var item_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var list

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var list_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var tag_color

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]

Methods

def get_next_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_next_by_due_date(self, *, field=<django.db.models.fields.DateField: due_date>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_next_by_finished_on(self, *, field=<django.db.models.fields.DateTimeField: finished_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_due_date(self, *, field=<django.db.models.fields.DateField: due_date>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_finished_on(self, *, field=<django.db.models.fields.DateTimeField: finished_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
class ListTags (*args, **kwargs)

ListTags(id, user_id, tag_name, created_on)

Expand source code
class ListTags(models.Model):
    user_id = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)
    tag_name = models.CharField(max_length=50, null=True, blank=True)
    created_on = models.DateTimeField()

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.tag_name

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var created_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var tag_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var user_id

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var user_id_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]

Methods

def get_next_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
class SharedList (*args, **kwargs)

SharedList(id, user, shared_list_id)

Expand source code
class SharedList(models.Model):
    user = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)
    shared_list_id = models.CharField(max_length=200)

    objects = models.Manager()

    def __str__(self):
        return "%s" % str(self.user)

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var shared_list_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var user_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
class SharedUsers (*args, **kwargs)

SharedUsers(id, list_id, shared_user)

Expand source code
class SharedUsers(models.Model):
    list_id = models.ForeignKey(List, on_delete=models.CASCADE)
    shared_user = models.CharField(max_length=200)

    objects = models.Manager()

    def __str__(self):
        return "%s" % str(self.list_id)

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var list_id

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var list_id_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var shared_user

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
class Template (*args, **kwargs)

Template(id, title_text, created_on, updated_on, user_id)

Expand source code
class Template(models.Model):
    title_text = models.CharField(max_length=100)
    created_on = models.DateTimeField()
    updated_on = models.DateTimeField()
    user_id = models.ForeignKey(
        User, on_delete=models.CASCADE, null=True, blank=True)

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.title_text

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var created_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var templateitem_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related objects through the reverse relation.

    With the example above, when getting ``parent.children``:

    - ``self`` is the descriptor managing the ``children`` attribute
    - ``instance`` is the ``parent`` instance
    - ``cls`` is the ``Parent`` class (unused)
    """
    if instance is None:
        return self
    key = self.related_manager_cache_key
    instance_cache = instance._state.related_managers_cache
    if key not in instance_cache:
        instance_cache[key] = self.related_manager_cls(instance)
    return instance_cache[key]
var title_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var updated_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var user_id

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var user_id_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]

Methods

def get_next_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_next_by_updated_on(self, *, field=<django.db.models.fields.DateTimeField: updated_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_updated_on(self, *, field=<django.db.models.fields.DateTimeField: updated_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
class TemplateItem (*args, **kwargs)

TemplateItem(id, item_text, created_on, template, finished_on, due_date, tag_color)

Expand source code
class TemplateItem(models.Model):
    item_text = models.CharField(max_length=100)
    created_on = models.DateTimeField()
    template = models.ForeignKey(Template, on_delete=models.CASCADE)
    finished_on = models.DateTimeField()
    due_date = models.DateField()
    tag_color = models.CharField(max_length=10)

    objects = models.Manager()

    def __str__(self):
        return "%s" % self.item_text

Ancestors

  • django.db.models.base.Model

Class variables

var DoesNotExist

The requested object does not exist

var MultipleObjectsReturned

The query returned multiple objects when only one was expected.

var objects

Instance variables

var created_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var due_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var finished_on

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var item_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var tag_color

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]
var template

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

Expand source code
def __get__(self, instance, cls=None):
    """
    Get the related instance through the forward relation.

    With the example above, when getting ``child.parent``:

    - ``self`` is the descriptor managing the ``parent`` attribute
    - ``instance`` is the ``child`` instance
    - ``cls`` is the ``Child`` class (we don't need it)
    """
    if instance is None:
        return self

    # The related instance is loaded from the database and then cached
    # by the field on the model instance state. It can also be pre-cached
    # by the reverse accessor (ReverseOneToOneDescriptor).
    try:
        rel_obj = self.field.get_cached_value(instance)
    except KeyError:
        has_value = None not in self.field.get_local_related_value(instance)
        ancestor_link = (
            instance._meta.get_ancestor_link(self.field.model)
            if has_value
            else None
        )
        if ancestor_link and ancestor_link.is_cached(instance):
            # An ancestor link will exist if this field is defined on a
            # multi-table inheritance parent of the instance's class.
            ancestor = ancestor_link.get_cached_value(instance)
            # The value might be cached on an ancestor if the instance
            # originated from walking down the inheritance chain.
            rel_obj = self.field.get_cached_value(ancestor, default=None)
        else:
            rel_obj = None
        if rel_obj is None and has_value:
            rel_obj = self.get_object(instance)
            remote_field = self.field.remote_field
            # If this is a one-to-one relation, set the reverse accessor
            # cache on the related object to the current instance to avoid
            # an extra SQL query if it's accessed later on.
            if not remote_field.multiple:
                remote_field.set_cached_value(rel_obj, instance)
        self.field.set_cached_value(instance, rel_obj)

    if rel_obj is None and not self.field.null:
        raise self.RelatedObjectDoesNotExist(
            "%s has no %s." % (self.field.model.__name__, self.field.name)
        )
    else:
        return rel_obj
var template_id

Retrieve and caches the value from the datastore on the first lookup. Return the cached value.

Expand source code
def __get__(self, instance, cls=None):
    """
    Retrieve and caches the value from the datastore on the first lookup.
    Return the cached value.
    """
    if instance is None:
        return self
    data = instance.__dict__
    field_name = self.field.attname
    if field_name not in data:
        # Let's see if the field is part of the parent chain. If so we
        # might be able to reuse the already loaded value. Refs #18343.
        val = self._check_parent_chain(instance)
        if val is None:
            instance.refresh_from_db(fields=[field_name])
        else:
            data[field_name] = val
    return data[field_name]

Methods

def get_next_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_next_by_due_date(self, *, field=<django.db.models.fields.DateField: due_date>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_next_by_finished_on(self, *, field=<django.db.models.fields.DateTimeField: finished_on>, is_next=True, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_created_on(self, *, field=<django.db.models.fields.DateTimeField: created_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_due_date(self, *, field=<django.db.models.fields.DateField: due_date>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)
def get_previous_by_finished_on(self, *, field=<django.db.models.fields.DateTimeField: finished_on>, is_next=False, **kwargs)
Expand source code
def _method(cls_or_self, /, *args, **keywords):
    keywords = {**self.keywords, **keywords}
    return self.func(cls_or_self, *self.args, *args, **keywords)