Skip to content

Instantly share code, notes, and snippets.

@ashchristopher
Created August 7, 2012 14:31
Show Gist options
  • Select an option

  • Save ashchristopher/3285855 to your computer and use it in GitHub Desktop.

Select an option

Save ashchristopher/3285855 to your computer and use it in GitHub Desktop.
Django Model definition?
class ModelTestCase(TestCase):
def test_1(self):
class Foo(object):
arg1 = "str"
arg2 = 1
class Bar(models.Model):
active = models.BooleanField()
print "Foo_id={0}, Bar_id={1}".format(id(Foo), id(Bar))
def test_2(self):
class Foo(object):
arg1 = "str"
arg2 = 1
class Bar(models.Model):
active = models.BooleanField()
print "Foo_id={0}, Bar_id={1}".format(id(Foo), id(Bar))
Output
------
nosetests --verbosity 1 partition_utils -s
Foo_id=206657676, Bar_id=206658540
.Foo_id=206609932, Bar_id=206658540
.
----------------------------------------------------------------------
Ran 2 tests in 0.002s
*** Notice that Bar has the same id in both tests, so the model isn't being re-defined. ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment