Oops, taking a second look, I think you are right, the object I was using to test that had its __unicode__ method calling something that shouldn't exist yet. I guess this example was not complex enough.
However, I think that I have figured out the problem. Model validation was introduced in the latest patch, but I don't really understand how it is different from what was before (not much explanation in the docs). However, it seems that in ModelForms, clean() calls self.instance.full_validate(). The problem with this is that I don't necessarily have a >saved< instance assigned to the model yet. I don't have enough data to save it before the form is evaluated! It seems that I can work around this behavior by writing an overloaded full_validate on my model, but this sounds flakey to me. Any thoughts? Thanks, -A.M. On Jan 5, 5:53 am, Russell Keith-Magee <freakboy3...@gmail.com> wrote: > On Tue, Jan 5, 2010 at 5:52 PM, Aristotle Miternan <hypersp...@gmail.com> > wrote: > > Hello everyone, > > > The latest update to django 1.2 broke my code and I'm hesitant to > > post it as a bug when I'm not sure if there's a core concept that > > changed that I don't get. > > > I noticed that I am no longer able to do this: > > > class Foo(models.Model): > > foo = models.CharField(max_length=30) > > > def __unicode__(self): > > return u"%s" % foo > > > print Foo() > > > I am getting a DoesNotExist exception when I haven't even touched > > the database yet! > > I don't see this error with your sample code and r12103. However, I > *do* see a NameError - because your __unicode__ method references foo, > not self.foo. > > > Some of my code depends on this behavior (ie foo.save > > (commit=False) ) so I can patch it with data that's not supposed to be > > defined by the user after it comes out of a modelform. Perhaps my > > technique is weak, but nonetheless I find this behavior strange. > > > Is it just me? > > I suspect there is something else going on. Foo() should be > instantiating an empty object. It shouldn't be performing any database > queries. Printing Foo() shouldn't be performing any database queries, > either. I don't doubt that you're seeing an error, but the cause isn't > as simple as you describe. > > Yours, > Russ Magee %-)
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.