1
votes

This is the error I am getting while creating an object in django. I know there is a mistake in defining the unicode for that particular model. But, I don't know how to define one for ManyToManyField in django.

Here are the revelant screenshots 'This is the UserProfile Model

This is the Purchases Model where the mistake is

The Error

1
Can you include the traceback below the yellow area in your screenshot? Without it there's no easy way to figure out where the problem lies. Looking at your models, the data design seems a bit off-- at least one of those ManyToMany fields feels like it should be a ForeignKey. Either way you don't want to be putting curruser in the __unicode__ method as that's not going to have a useful value-- it's the model manager, not a string. I think you want a ForeignKey there. - Tom
@Tom, thank you. It worked. I just changed one of those fields into ForeignKey relation and it worked :) - user6508070

1 Answers

1
votes

I've incurred in the same "maximum recursion depth exceeded" issue today and I realized that my IDE generated automatically this method for my Model.

def __str__(self):
    return super(MyModel, self).__str__()

This is one the main reasons the maximum recursion might be raised, when a method/function triggers a loop of invocations without any control.

Perhaps this happens when the Purchases.unicode asks for the unicode from the UserProfile, which again asks for a descriprion (unicode or str, I hope, from a django relation which is basically a django Field, from django/db/models/fields )