X
X
XisterONE2017-06-25 23:43:01
Django
XisterONE, 2017-06-25 23:43:01

Can't do a search?

Help plz. Here is the model for which you need to search

class Task(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1, verbose_name="Автор")
    category = models.ForeignKey(Category, related_name='tasks', verbose_name="Категория")
    name = models.CharField(max_length=200, db_index=True, verbose_name="Название")
    slug = models.SlugField(max_length=200, db_index=True)
    description = models.TextField(blank=True, verbose_name="Описание")
    created = models.DateTimeField(auto_now_add=True, verbose_name='Создан')
    updated = models.DateTimeField(auto_now=True, verbose_name='Обновлен')

views.py
def TaskList(request, category_slug=None):
    category = None
    categories = Category.objects.all()
    tasks = Task.objects.all()
    if category_slug:
        category = get_object_or_404(Category, slug=category_slug)
        tasks = tasks.filter(category=category)
    paginator = Paginator(tasks, 2)
    page = request.GET.get('page')
    try:
        tasks = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        tasks = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        tasks = paginator.page(paginator.num_pages)
    return render(request, 'list.html', locals())


# Страница товара
def TaskDetail(request, id, slug):
    task = get_object_or_404(Task, id=id, slug=slug)
    return render(request, 'detail.html', locals()

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