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

  • Home
  • SEARCH
  • 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 3947502
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:15:32+00:00 2026-05-20T01:15:32+00:00

I am trying to use django-tables to create a sortable table out of some

  • 0

I am trying to use django-tables to create a sortable table out of some Models.

http://elsdoerfer.name/docs/django-tables/types/models.html#spanning-relationships says that I can span through relationships, but I have difficulty doing it “backwards”.

Here are my models and the table:

class Book(Model):
    isbn = ISBNField("ISBN", primary_key=True, editable=True, blank=True, null=False)

class SomeInfo(Model):
    book = OneToOneField(Book, primary_key=True, editable=False, blank=False, null=False, verbose_name = _('ISBN'), related_name='someinfo')
    title = CharField(_("Title"), editable=False, blank=False, null=True, max_length=250)

class MyInfo(Model):
    book = OneToOneField(Book, primary_key=True, editable=False, blank=False, null=False, verbose_name = _('ISBN'), related_name='myinfo')
    average_price = DecimalField(_("Average price"), editable=False, null=True, max_digits=6, decimal_places=2)

class Query(Model):
    book = ForeignKey(Book, editable=True, blank=True, null=True, verbose_name = _('ISBN'))
    max_price = DecimalField(_('Maximum price'), null=True, max_digits=6, decimal_places=2)

class MyTable(ModelTable):
    my_average_price = tables.Column(data="book__myinfo__average_price")
    my_title = tables.Column(data="book__someinfo__title")
    class Meta:
        model = Query

When trying to use for example my_average_price in a template, I get this error:

TemplateSyntaxError at /list/

Caught ValueError while rendering: Could not resolve myinfo from book__myinfo__average_price

Any ideas how to make it work?

All columns, also the ones from the related relationships, need to be sortable.

  • 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-05-20T01:15:33+00:00Added an answer on May 20, 2026 at 1:15 am

    This works for me, provided that a related SomeInfo or MyInfo instance exists. The error should only be raised if that is not the case. I.e., each book in the table would need to have SomeInfo and MyInfo attached.

    This is because the code in django_tables/models.py:BoundModelRow._default_render will raise this error if one of the attributes in the chain does not exist, which is the case here if a related instance is missing: Book.myinfo does not exist as an attribute if no MyInfo exists for the Book instance.

    This would probably need to be considered a bug in django-tables. Rather than just reversing through the object attributes, it should look at instance._meta at which database fields have actually been defined. If it determines that a reverse OneToOne accessor exists, but no corresponding attribute does, it would then just assume a null value rather than raising an exception.

    I’ve reported this as a bug here: https://github.com/miracle2k/django-tables/issues/issue/11 However, I’m not sure when I’ll get to work on it. Patches are certainly welcome.

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

Sidebar

Related Questions

I'm trying to practice some django basics by implementing my own sortable table in
I am trying to use django-socialauth ( http://github.com/uswaretech/Django-Socialauth ) for authenticating users for my
I'm trying to use the Django ORM in some standalone screen scraping scripts. I
I am learning Django and I am trying to understand the use of models.py
I'm trying to use django-ajax-related-fields, and the foreignkey field I'm trying to create a
I'm trying to use Django to display a table of information from across several
I am trying to figure out how to use proxy classes in Django. I
I am trying to use Django to create a recursive relationship, which gives users
I am trying to use django-social-auth to implement google openid login into my app,
I have a small app I'm working on where I'm trying to use Django's

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.