On Mon, Oct 13, 2008 at 4:22 AM, Alessandro Ronchi <
[EMAIL PROTECTED]> wrote:

> 2008/10/11 Karen Tracey <[EMAIL PROTECTED]>:
>
> > You've got a typo in there somewhere, because there is no 'notizie' in
> the
> > query you posted, you've got 'schede' like above.  So I'm not sure
> exactly
> > what you tried nor exactly what error you got.  Cut and paste of code and
> > error messages is best to avoid confusion.  Also, posting complete models
> > instead of just snippets (put them out on dpaste.com and point to them
> if
> > they are non-trivial and thus will display poorly in email) may be better
> in
> > this case.  From what you posted so far I don't see why what (I'm
> guessing)
> > your query was isn't working.
>
> This is my models.py:
> http://dpaste.com/84075/
>
> This is my urls.py:
> http://dpaste.com/84077/
> (che commented line is the one that gives the error)
> #
> ultima_edizione=Edizione.objects.distinct().filter(notizie__isnull=False).order_by('-id')
>
>
> This is the error i Get:
>
> http://dpaste.com/84076/
>
> Thanks in advance!
>

I can't recreate your error because any attempt to use the models.py you
point to produces an error on the declaration of the Edizione ForeignKey
field within model Notizia:

    edizione = models.ForeignKey(Edizione, related_name="notizie",
default=ultima_edizione)
NameError: name 'ultima_edizione' is not defined

So I am not sure exactly how you are getting as far as you are with this
models.py.  (It's also missing any declaration of the model Download that is
referenced in the urls.py you point at...) But I think you have a
chicken-and-egg sort of problem since the line you are saying does not work
is:

ultima_edizione=Edizione.objects.distinct().filter(notizie__isnull=False).order_by('-id')

So loading the Notizia model requires resolving ultima_edizione, but
ultima_edizione requires the Notizia model to be fully initialized since it
is the Edizione ForeignKey within Notizia which causes the 'notizie'
attribue to be added to Edizione.  (Also, even if this worked,
ultima_edizone ends up being a QuerySet there, not an Edizione instance, so
it wouldn't work as a default value.)

Simply adding an import of the missing ultima_edizione to models.py produces
an import error that Notizia cannot be imported due to the circular
reference, in the backtrace you see:

    from urls import ultima_edizione
...
    from models import Notizia, Edizione
...
    from urls import ultima_edizione
...
    from models import Notizia, Edizione
ImportError: cannot import name Notizia

which is what I would expect given what you have.  So I'm not sure how you
are getting around the circular import but it seems to result in
ultima_edizione being processed using an incompletely loaded model set,
since Edizione does not have the attribute that will be created when the
Notzia model is loaded.

I think you need to take a step back and rethink that default= on the
edizione ForeignKey.  What are you really trying to accomplish?

Karen

--~--~---------~--~----~------------~-------~--~----~
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