On Mon, May 2, 2011 at 5:49 AM, Nick <n...@njday.com> wrote:

> I'm having a very strange problem with a site I've developed, which
> only seems to happen when DEBUG=False and is now preventing my from
> launching the site (unless I launch it in DEBUG mode, which I
> obviously don't want to).  The EXACT same code works in DEBUG=True,
> but with DEBUG=False I get the following error when trying to access
> one of my ManyToMany fields:
>
> views.py - FieldError: Cannot resolve keyword 'page' into field.
> Choices are: bank_holidays, date_values, finish, id, start, values,
> year
>
> I have discovered that if I comment out my admin.autodiscover() line
> in urls.py it suddenly starts working again.  I've therefore looked at
> my admin.py and simplified it to a very basic example, but this still
> doesn't work.  Here are the relevant parts of my code (let me know if
> there are any other parts that would be useful to see)...
>
> models.py: http://dpaste.com/hold/537990/
> views.py: http://dpaste.com/537991/
> admin.py: http://dpaste.com/hold/537993/
>
> So as soon as I try and lookup page.years.all() in my page view I get
> an error.  If I don't import any models in my admin.py (I've tried
> removing the whole admin.py file) then I can lookup page.years.all()
> without any issues.  Weird!  Maybe some sort of circular import issue
> or something?  I've been looking at this for 6 hours and can't see a
> solution so any help would be great!
>

Your ForeignKey fields are using quoted strings for references to models,
this can trigger problems like this (see ticket #10405, though in that
particular case the error message is different). Since you don't seem to
have any need to do that (the Year model is in the same file as the other
models and defined first, so you can just as easily specify Year as "Year"
for the related model in the ForeignKey definitions) I'd stop doing that and
see if the problem goes away.

If not, problems like this also come from intermixing model and form
definitions (see ticket #11247 and the one it was closed dupe of). From a
brief scan I don't see that you are doing that, but you have included an
import of django forms in your models.py which makes me wonder if perhaps
you are doing something like that in the full version of the code. Avoiding
model/form intermixing is then the 2nd thing I'd try to fix the problem.

Karen
-- 
http://tracey.org/kmt/

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to