On Feb 10, 2008 9:50 AM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
>
> On Sun, 2008-02-10 at 09:27 -0500, Prof. William Battersea wrote:
> > Hello,
> >
> > I created a Django application, validated it for errors and ran syncdb
> > without any problems. I can click into the admin section but as soon
> > as I click "Add" for one of my models I get the error
> > AttributeError at /admin/gallery/gallery/add/
> > 'str' object has no attribute 'creation_counter'
> > Request Method:       GET
> > Request URL:  http://localhost/admin/gallery/gallery/add/
> > Exception Type:       AttributeError
> > Exception Value:      'str' object has no attribute 'creation_counter'
> > Exception Location:
> >       C:\Python25\lib\site-packages\django\db\models\fields\__init__.py in
> > __cmp__, line 100
> >
> > This line is:
> >   def __cmp__(self, other):
> >        # This is needed because bisect does not take a comparison function.
> >        return cmp(self.creation_counter, other.creation_counter)
> >
> > I'm having a hard time troubleshooting this. My models look fine to me.
>
> So you're quite familiar with your models and cannot see the problem. We
> are not familiar with them, but only get shown the last line of the
> traceback. It seems like one party has a lot more information than the
> other here. :-)
>
> If your model is short (and preferably, try to reduce your example to a
> very short case that still fails), post the model.
>
> Also, look at the full traceback in the debug screen, go to the last
> line and click on the local variables button. You'll be able to see what
> "self" and "other" are. One of them *won't* be a Field class, although
> it should be (since creation_counter is an attribute on the Field
> class). That might give you some clues as to what is going wrong.
> Somehow you are managing to get a string into somewhere that a Field
> class (or subclass) is expected.
>
> Do you have a custom save() method involved here at all? It's going to
> be something like that, since it's not the field definitions themselves
> (the model validated).
>
> Sorry I can't offer an immediate solution, but the lack of information
> is hurting us a bit here.
>
> Regards,
> Malcolm
>
> --
> Save the whales. Collect the whole set.
> http://www.pointy-stick.com/blog/
>
>
> >
>

Heh. Sorry I didn't want to just throw all my code at someone. I was
hoping it was a common problem. While I was trying to put more
information into this email, I think I solved the problem.

I had a Model called Gallery, which had a ManyToManyField pointing to
a Model called Location. In location, I had set my __str__ method to:

return " / ".join(str(v) for v in self.location if not v == "")

Thinking that it would be handy to have these display in a default
format of Country / State / City. (location in the line above is a
list containing Country,State and City variables, any of which can be
blank)
I noticed that although Locations were saving, I was getting the same
error on the save page and a listing of (None) on the locations page.
So I switched the __str__ method in Location to return self.country
and everything seems to work.

What did I mess up by overriding the __str__ method originally?
I did have a custom save method in my Gallery model too.

Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to