Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:58:55+00:00 2026-06-13T00:58:55+00:00

I have two models news.article and portfolio.entry. Both models have a BooleanField for setting

  • 0

I have two models news.article and portfolio.entry. Both models have a BooleanField for setting “is_campaign” to true.

Im trying to write a custom templatetag so I can get the latest campaign article (There should only be one)

Here is my templatetag: campaign_article.py

from itertools import chain
from django import template

from news.models import Article
from portfolio.models import Entry

register = template.Library()

def get_campaign():
        #Get the newest news article with is_campaign=True
        article = Article.objects.filter(is_campaign=True).order_by('-pub_date')[:1]

        #Get the newest portfolio entry with is_campaign=True
        portfolio = Portfolio_entry.objects.filter(is_campaign=True).order_by('-pub_date')[:1]

        #combine article, and entry and display only the newest
        campaign_article = list(chain(article, portfolio))[:1]


        return {'campaign_article': campaign_article}



register.tag('campaign', get_campaign)

I have tried this in my template:

{% load campaign_article %}
{% for campaign_article in campaign %}

{{ campaign_article.id }}

{% endfor %}

But I don’t get any output. Is this the wrong method ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:58:56+00:00Added an answer on June 13, 2026 at 12:58 am

    You would want to create assignment_tag rather than a generic tag.
    So you can update your tag as:

    def get_campaign():
        #your stuff
        ....
    
        return campaign_article
    
    register.assignment_tag(get_campaign, name='campaign')
    

    And update template as:

    {% load campaign_article %}
    {% campaign as campaign_list %} {# loads the tags and creates campaign_list context variable #}
    {% for campaign_article in campaign_list %}
        {{ campaign_article.id }}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, Article and Post that both inherit from a base model
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have two models: class Video(models.Model): slug = models.SlugField(blank=True, default='', db_index=True, unique=True) class VideoTranslation(models.Model):
I have two models: ServiceViewModel and ReservationsViewModel; both are based on the tutorials found
I have two projects: News.Data Tags.Data Both define Entities . When I try to
I have two models Customer and Referal. Both have an email attribute. Referal belongs
I have two models: class Studio(models.Model): name = models.CharField(Studio, max_length=30, unique=True) class Film(models.Model): studio
I have two models in the same application. The application is called News, and
I have two models indexed for searching (User and Item). I'm trying to do
I have two models, Listing and Invitation, associated with has_and_belongs_to_many. I am looking at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.