Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!
I'm having a problem making my first Django Model class save(). I keep getting an AttributeError with the message: 'Foo' object has no attribute 'id'

The docs make it pretty clear that you don't have to specify an id field, that it'll add one for you if you don't, so what could be keeping it from working?

I'm using a Manager, I have a Meta class that sets a different db_table and an __init__ that sets all the fields, but nothing else that's all that complicated. Any ideas?

Also, I just started using Python last week to play around with the Google App Engine and got hooked on Django this week, it's pretty sweet. Seems to make things just about as easy as possible, I think. Except, of course, when none of your objects will save :(

Adbot
ADBOT LOVES YOU

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

bitprophet posted:

Please paste (or pastebin, e.g. dpaste.com) your model code? Hard to troubleshoot without.

Been a while since I tinkered with save() but I am reasonably sure objects do not get an id until after their first save, so depending on what you're doing that might be the issue. Also, "an __init__ that sets all the fields" could be dangerous depending on what that means exactly, which is another reason I'd like to see your code :shobon:

http://dpaste.com/45833/

I changed it __init__ to a method, in case that was the problem, and it appears to at least be getting further. Now the problem is:
code:
>>> game = Game()
>>> game.parse_log_line('3.3.1 118 0 1 1 0 11 1 20011024 20011024 1031 Rog Orc Fem Cha jorko,killed by a jackal')
>>> game.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Python/2.5/site-packages/django/db/models/base.py", line 238, in save
    ','.join(placeholders)), db_values)
  File "/Library/Python/2.5/site-packages/django/db/backends/util.py", line 12, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Python/2.5/site-packages/django/db/backends/sqlite3/base.py", line 93, in execute
    return Database.Cursor.execute(self, query, params)
InterfaceError: Error binding parameter 15 - probably unsupported type.

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

deimos posted:

Try switching the 0 and 1 to true and false, maybe it forgets to do a type check before turning it into a string. Not sure if SQLite shits itself when you try to set a boolean field to 0 or 1.


also what the christ self._aligns.keys().index(chunks[14]) is just self._align[chunks[14]].

Which 0 and 1s? The only boolean field I have is already set with True and False.

_aligns is a dictionary, and I need to store the index of the matching key, not the value of it. It's a dictionary because later on when I output the results I'll want the full value and not the abbreviated one that's in the logs.

ImJasonH fucked around with this message at 22:06 on Apr 19, 2008

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

deimos posted:

Your code somewhat stinks of SAVAGELY OPTIMIZED overtones.

You're probably right, I could probably save myself a lot of trouble by just storing strings in the database instead of ints. In fact, yeah, I'm going to tweak this some and simplify.

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

deimos posted:

I am not against storing ints where ints are due, but making them small or large really isn't saving you a lot. Still I'd love to know if it's some sort of backend issue with django so that a proper ticket can be opened.

Not a backend issue, just my own stupidity. I was passing a list of strings to killed_by because i r dum.

Adbot
ADBOT LOVES YOU

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

politicorific posted:

I can define "englishdictionary" in views.py to be any letter I want, but how do I get django to determine the variable based on the url?

I think Named Groups is the solution, read the section on them here

Basically, change the line in urls.py to:
code:
(r'^english/(?P<letter>\w)/', englishdictionary))
And now the letter in /english/x/ will be available as a parameter in your view:

code:
def englishdictionary(request, letter):
    pass
edit: This may not be perfect because I'm pretty new to Django and horrible at regexps, but you get the point.

ImJasonH fucked around with this message at 05:33 on May 4, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply