R
R
Radiss2020-08-24 23:10:07
Django
Radiss, 2020-08-24 23:10:07

Error with django-taggit - how to fix?

Why doesn't Django define TodoItem in TaggableManager?
I'm trying to change object tags. The application has 1 task.

I run the python manage.py shell

>>> from tasks.models import TodoItem
>>> t = TodoItem.objects.get(pk=1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/user/Home/ASITES/python/12v/my-venv/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/user/Home/ASITES/python/12v/my-venv/lib/python3.6/site-packages/django/db/models/query.py", line 399, in get
    self.model._meta.object_name
tasks.models.TodoItem.DoesNotExist: TodoItem matching query does not exist.
>>>


models.py

from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User
from taggit.managers import TaggableManager


class TodoItem(models.Model):

    PRIORITY_HIGH = 1
    PRIORITY_MEDIUM = 2
    PRIORITY_LOW = 3

    PRIORITY_CHOICES = [
        (PRIORITY_HIGH, "Высокий приоритет"),
        (PRIORITY_MEDIUM, "Средний приоритет"),
        (PRIORITY_LOW, "Низкий приоритет"),
    ]

    tags = TaggableManager(),

    description = models.CharField(max_length=64)
    is_completed = models.BooleanField("выполнено", default=False)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    owner = models.ForeignKey(
        User, on_delete=models.CASCADE, related_name="tasks")
    priority = models.IntegerField(
        "Приоритет", choices=PRIORITY_CHOICES, default=PRIORITY_MEDIUM
    )

    def __str__(self):
        return self.description.lower()

    class Meta:
        ordering = ("-created",)

    def get_absolute_url(self):
        return reverse("tasks:details", args=[self.pk])

    class Widget(models.Model):
        name = models.CharField(max_length=50)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question