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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:52:41+00:00 2026-05-26T15:52:41+00:00

Have a class definition that looks something like this class someClass(models.Model): field1 = models.ForeignKey(‘other_app.field4’)

  • 0

Have a class definition that looks something like this

class someClass(models.Model):
    field1 = models.ForeignKey('other_app.field4')
    field2 = models.ManyToManyField('other_app.field5')
    variable_name  = [1-char choices]
    field3 = models.CharField(max_length=1, choices=variable_name, blank=True)

When I try to edit this class in the admin panel, I get:

TypeError at /admin/[app]/[someClass]/add/

Assume it has to do with the ManytoMany field, any obvious workarounds?


UPDATE: Ok, so I figured out the issue: the code that my partner had written had an iterative __str__ function:

def __str__(self):
    str_rep = '%s for ' % (self.field1)
    for p in self.field2:
        str_rep += str(p) + self.field3

Any ideas on how to rewrite this?

  • 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-26T15:52:42+00:00Added an answer on May 26, 2026 at 3:52 pm

    In the future, try posting an actual traceback and the relevant lines of code. It would have shown us exactly where this code was breaking.

    field2 is not iterable. You need to get a QuerySet from your ManyRelatedManager by calling all() or filter(...).

    https://docs.djangoproject.com/en/dev/topics/db/queries/#many-to-many-relationships

    def __str__(self):
        str_rep = '%s for ' % (self.field1)
        for p in self.field2.all():
            str_rep += str(p) + self.field3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template class that looks something like this: template<class T> class C
I have an object model that looks like this: public class MyObjectModel { public
I'm trying to build an object that looks something like this: public class MyObject
Let's say I have an object who's class definition looks like: class Command: foo
Basically I have code which looks like this inside a header file: class Bar;
This is something that I never ran into before. Say I have a class
I have a header file that looks like header.h int TOS; This file is
Anyone knows if is possible to have partial class definition on C++ ? Something
Let's have the following class definition: CThread::CThread () { this->hThread = NULL; this->hThreadId =
I have three coffeescript classes, set up like this: class A class C extends

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.