﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
382	globals should show up in model methods and classes (like normal python classes)	brenocon@…	Adrian Holovaty	"I want to do this:


{{{
import re

class Note(meta.Model):
  #...
  def __repr__(self):
    if re.search(...)

}}}


Unfortunately, ""re"" isn't present in the namespace.  The following exception occurs:


{{{
  File ""c:\brendano\djblog\apps\blog\models\blog.py"", line 25, in __repr__
    if re.search(r'^\s*$', self.title):

NameError: global name 're' is not defined

}}}

as a workaround I can just do ""import re"" inside the method.  But the larger problem is, all module-level (global) variables don't appear inside any method namespaces.

{{{
myglobal = 5
class Note(meta.Model):
  #...
  def __repr__(self):
    print myglobal
}}}

also gives the same error.  In fact, a manual ""global myglobal"" statement fails to make it work.

IMPORTANCE: so I guess the preferred django way of doing things is to make the model classes as sparse and declarative as possible.  In that case the bug is a minor inconvenience.

SUSPECTED CAUSE: maybe a bug in the ModelBase metaclass?

SVN version: 541"	defect	closed	Core (Other)		minor	wontfix		brenocon@…	Unreviewed	0	0	0	0	0	0
