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 8555631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:10:04+00:00 2026-06-11T15:10:04+00:00

I have a list of objects. I want to display these objects in such

  • 0

I have a list of objects. I want to display these objects in such a way that only the first unique date displays if the subsequent objects contain the same date. If the date is different than it should display. Here is an example.

data:

  • id: 2, date: “01/01/2010”
  • id: 3, date: “01/01/2010”
  • id: 4, date: “02/02/2010”

What I want to display:

  • id – 2, “01/01/2010”
  • id – 3,
  • id – 4, “02/02/2010”

See how id 3 shows nothing since the previous date was the same?

How do I do this with django templates? One thing I tried was creating a custom filter. The only problem is that it uses a global variable which is a no-no in my opinion. How can I maintain state in a function filter or in django templating language to be concious of the previous value?

__author__ = 'Dave'
#This works but isn't best practice
from django import template
register = template.Library()

a = ''
@register.filter()
def ensure_unique(value):
    global a
    if a == value:
        return ''
    else:
        a = value
        return value
  • 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-11T15:10:06+00:00Added an answer on June 11, 2026 at 3:10 pm

    Using a simple_tag made it much easier for me to save state and accomplish exactly what I needed to.

    from django import template
    register = template.Library()
    
    @register.simple_tag(takes_context=True)
    def stop_repeat(context, event):
        """
        Finds various types of links embedded in feed text and creates links out of them.
        """
        if event.date:
            if (event.get_date_time_location(), event.id) in context:
                return ''
            else:
                context[(event.get_date_time_location(), event.id)] = (event.get_date_time_location(), event.id)
                return event.get_date_time_location()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation where I want to display a list of Administration objects
I have a list of objects and I want to remove all the ones
I have a list of objects which I want to turn into a set.
I have a List which contains a list of objects and I want to
I have a list of person objects which I want to send in response
I have a list of objects with property id and parent_id. I want to
I have a list of objects, some of which can be null. I want
I have a web service that returns a super simple list of objects MyObject[]
I have a List of objects and a ListView where I display this list.
So, events bubble up the display list. That's great if that's what you want.

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.