Wagtail CMS: Registering Snippets (Blog Category) using Checkboxes

Поділитися
Вставка
  • Опубліковано 6 вер 2024

КОМЕНТАРІ • 12

  • @hamednajand8327
    @hamednajand8327 4 роки тому +5

    You're awesome! the way you teach is the one way that I'm exciting to follow and in fact, I don't sleep during the video :))

  • @nooralqoj4575
    @nooralqoj4575 3 роки тому +1

    Great tutorial and amazing instructor :)
    I click like button before I watch the videos !!

  • @IllevensKO
    @IllevensKO 4 роки тому +1

    Is there any way to use tag chooser panel style ? Can't find anything about it.

  • @goneforawander_com
    @goneforawander_com 3 роки тому

    Great tutorial, especially working out the filtering by category. Immensely useful :)
    Probably wouldn't be trusting content editors to make slugs though 😂 I went with the autoslug field from django extensions:
    from django_extensions.db.fields import AutoSlugField
    ...
    slug = AutoSlugField(
    populate_from=['name'],
    verbose_name='slug',
    allow_unicode=True,
    max_length=200,
    )
    then drop slug from the panel

  • @Cosas1008
    @Cosas1008 3 роки тому

    filter inspired by Kalob
    if request.GET.get('category'):
    context["posts"] = BlogDetailPage.objects.live().public().filter(categories__slug__in=[request.GET.get('category')])
    else:
    context["posts"] = BlogDetailPage.objects.live().public()

  • @boryskuczkowski
    @boryskuczkowski 5 років тому +1

    @15:45 Have you, eventually, implemented the filter?

    • @CodingForEverybody
      @CodingForEverybody  5 років тому +2

      Nope I don't believe so. But it'd be as easy as BlogDetailPage.objects.live().public().filter(categories__slug__in=[request.GET.get('category')]), or something along these lines. (Note: that's untested, so you may need to adjust it)

    • @DouglasMcKey
      @DouglasMcKey 4 роки тому +7

      I applied the filter my side, I used this:
      # Get all the blog posts.
      posts = BlogDetailPage.objects.live().public()
      # Identify recent posts and send to template:
      context["recent_posts"] = posts[:5]
      # Check if there is a category slug in the URL to filter the blog posts by.
      category_slug = request.GET.get("category", None)
      context["blog_posts"] = posts
      # By default - set to all posts
      if category_slug:
      # Must have a count > 0 in order to display something
      if posts.filter(categories__slug__contains=category_slug).count() > 0:
      context["blog_posts"] = posts.filter(categories__slug__contains=category_slug)
      else:
      context["blog_posts"] = posts # Seems like repetition but it caters for the 0 count on a blog_slug.
      ** I used the context["recent_posts"] to create a latest 5 posts navigation on the right of my content. Reverse ordered in template.
      ** I used the context["blog_posts"] to actually filter the blog list view when certain categories were clicked. (Only displayed categories with more than 0 posts associated to them)

    • @goneforawander_com
      @goneforawander_com 3 роки тому

      @@DouglasMcKey using categories__slug__contains=category_slug doesn't work if the name of the category forms part of the name of other categories. It'll pick up all those categories instead of just the one you want. I tried this with having Education, Early Education, Environmental Education. When I went with ?=Education I got all 3 categories. Just categories__slug=category_slug works fine though.