Re: related_name in filter search

2008-10-13 Thread Karen Tracey
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
-~--~~~~--~~--~--~---



Re: related_name in filter search

2008-10-13 Thread Alessandro
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!


-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

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



Re: related_name in filter search

2008-10-13 Thread Alessandro Ronchi
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!

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

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



Re: related_name in filter search

2008-10-11 Thread Karen Tracey
On Fri, Oct 10, 2008 at 3:19 PM, Alessandro <[EMAIL PROTECTED]>wrote:

> In a project I have
> class Scheda(models.Model):
>referente = models.ForeignKey(User,related_name="schede",
> editable=False)
>
> and I can use:
> User.objects.distinct().filter(schede__isnull=False):
>
> in another I have
> class Notizia(models.Model):
>edizione = models.ForeignKey(Edizione, related_name="notizie",
> default=ultima_edizione)
>
> and
> Edizione.objects.distinct().filter(schede__isnull=False).order_by('-id')[0]
>
> returns
>
> FieldError: Cannot resolve keyword 'notizie' into field. Choices are:
> id, nome, slug
>

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.

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



Re: related_name

2007-08-06 Thread Lic. José M. Rodriguez Bacallao
right now, I find out how but, anyway, I'll give U an example:

every ForeigmKey have a related_name parameter in its constructor, the
problem is how to change that value once we construct the ForeignKey object.
I did so changing the value of the: foreignkey_object.rel.related_name at
runtime.

On 8/4/07, Amirouche <[EMAIL PROTECTED]> wrote:
>
>
>
>
> On Aug 1, 10:07 pm, "Lic. José M. Rodriguez Bacallao"
> <[EMAIL PROTECTED]> wrote:
> > how can I change the "related_name" value in a ForeignKey field
> dynamically
> > at model creation time?
> >
>
> What do you really mean I don't understand, give an example
>
>
> >
>


-- 
Lic. José M. Rodriguez Bacallao
Cupet
-
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
mismo.

Recuerda: El arca de Noe fue construida por aficionados, el titanic por
profesionales
-

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



Re: related_name

2007-08-04 Thread Amirouche



On Aug 1, 10:07 pm, "Lic. José M. Rodriguez Bacallao"
<[EMAIL PROTECTED]> wrote:
> how can I change the "related_name" value in a ForeignKey field dynamically
> at model creation time?
>

What do you really mean I don't understand, give an example


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