It's a simple and old bug.

If you do: mod = MyModel(anything=something)

It'll work as expected.  You need at least one keyword argument in there.
So, in your example:
"""mod = MyModel(foo_id=1)
mod.bar_id = 2
mod.save()"""
Works.

On 12/30/05, Wojtek/brandlay.com <[EMAIL PROTECTED]> wrote:
>
> So i did:
> def MyModel(meta.Model):
>  foo = meta.ForeignKey(Foo)
>  bar = meta.ForeignKey(Bar)
>  added = meta.Date(auto_add_now = True)
>
> mod = MyModel()
> mod.foo_id = 1
> mod.bar_id = 2
> mod.save()
>
> And it did not work, saying that my object has no 'id' attribute.  Why
> would it have an 'id' attribute since I just created it?
>
> So I added:
> mod.id = 0
>
> And it did not work, saying that the field 'added' isn't defined.  Why
> would it be defined if I set it to 'auto_add_now' so that Django
> automagically fills it with the current date?
>
> So I added:
> mod.added = 0
>
> And at last it worked.
>
> A few notes:
> 1. Why does the programmer have to bother so much and define those
> fields while django could do getattr(mod, 'id', None) and just assume
> that it's not there if it's not even defined?
> 2. Same thing with the 'added' field (note that I set it to 0 and it
> was treated as nonexsitant).
> 3. I'm not using the constructor since I don't want to do 2 selects in
> order to do one INSERT for performance reasons.
>
> This looks like a simple thing to 'fix', would be neat if you do it :)
>
> Best regards and a happy new year party :)
> W. Sobczuk
>
>

Reply via email to