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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:11:32+00:00 2026-06-02T23:11:32+00:00

Here’s my code: [{{thing.syncedthing_set.all.0.state}}] {% ifequal thing.syncedthing_set.all.0.state InProgress %} It worked {% endifequal %}

  • 0

Here’s my code:

[{{thing.syncedthing_set.all.0.state}}]
{% ifequal thing.syncedthing_set.all.0.state "InProgress" %}
    It worked
{% endifequal %}

The result:

[InProgress]

In other words, the variable lookup works, but isn’t passing the ‘ifequal’ test. I can’t think of any reason this wouldn’t work other than variable lookups not being supported.

There’s a mailing list message from 2007 saying they weren’t supported back then: https://groups.google.com/forum/?fromgroups#!topic/django-users/oU1im3UTcLc – is this still the case?

If so, any good workarounds? It’s not easy in this case to modify the Python code that calls the template.

If they ought to work – any other possible causes?

There’s this very similar question but the answer doesn’t work for me. I’m using Django 1.3.

EDIT

Ok, so the ‘state’ has type class. Looking up the definition, state refers to a class which eventually subclasses models.Field:

class FSMField(models.Field):
    __metaclass__ = models.SubfieldBase

    states = {}
    """ Contains { 'Statename': StateClass, ... }"""

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('max_length', 50)
        super(FSMField, self).__init__(*args, **kwargs)

    def to_python(self, value):
        if isinstance(value, State):
            return value
        return self.__class__.states.get(str(value))()

    def get_prep_value(self, value):
        return str(value)

    def get_internal_type(self):
        return 'CharField'

Given that – I’m actually not sure how to get a real string value in the templating system. Forgive my newbishness.

EDIT2
Actually, the relevant bit is probably the ‘State’ class itself:

class State(object):
    """ A simple finite statement machine abstract class, with on_entry and on_exit events."""
    def __unicode__(self):
        return "%s" % (self.__class__.__name__)

    def __str__(self):
        return "%s" % (self.__class__.__name__)
  • 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-02T23:11:34+00:00Added an answer on June 2, 2026 at 11:11 pm

    There’s a difference between an object’s string representation, and what it actually is. It seems likely that your state property returns an object whose unicode representation is InProgress, but that doesn’t make it actually equal to "InProgress". This would be true for example if state is a ForeignKey to another model – in which case you could just add another level to the lookup to get to the actual field that returns that status.

    Edit after update I think you’ve coded yourself into a corner, unfortunately. Since there’s no actual instance attribute that contains the state as a string, there’s no way to get it via string comparison.

    A couple of possibilities spring to mind. One is to pass all possible State subclasses to the template context (perhaps via a context processor), after which you’ll be able to compare your state with the actual objects. This is pretty horrible.

    An alternative would be to add a function, either on the State class or possibly on the model, which gets the state as a string. This could be as simple as the existing __unicode__ method (you can’t actually use that, because the template language forbids accessing attributes that begin with underscores). Then you can do ifequal foo.bar.0.state.as_string "InProgress" or whatever, and that will call the as_string() method and your comparison will succeed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: // Not all headers are relevant to the code snippet. #include
Here the total height of all <div> 's are 900 pixels, but the jQuery
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
Here is an example: I write html code inside of textarea, then I swap
Here is my code, which takes two version identifiers in the form 1, 5,
Here's a coding problem for those that like this kind of thing. Let's see
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is my code sample, let me know if it can be further improved?
Here is my code (Say we have a single button on the page that

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.