Fix for #41
This commit is contained in:
@@ -26,6 +26,10 @@ class hybrid_classmethod(object):
|
||||
else:
|
||||
return self.instmethod.__get__(instance, owner)
|
||||
|
||||
class QuerySetDescriptor(object):
|
||||
def __get__(self, obj, model):
|
||||
return QuerySet(model)
|
||||
|
||||
class BaseModel(object):
|
||||
"""
|
||||
The base model class, don't inherit from this, inherit from Model, defined below
|
||||
@@ -34,6 +38,8 @@ class BaseModel(object):
|
||||
class DoesNotExist(QueryException): pass
|
||||
class MultipleObjectsReturned(QueryException): pass
|
||||
|
||||
objects = QuerySetDescriptor()
|
||||
|
||||
#table names will be generated automatically from it's model and package name
|
||||
#however, you can also define them manually here
|
||||
table_name = None
|
||||
@@ -266,7 +272,6 @@ class ModelMetaClass(type):
|
||||
|
||||
#create the class and add a QuerySet to it
|
||||
klass = super(ModelMetaClass, cls).__new__(cls, name, bases, attrs)
|
||||
klass.objects = QuerySet(klass)
|
||||
return klass
|
||||
|
||||
|
||||
|
||||
@@ -479,3 +479,11 @@ class TestValuesList(BaseQuerySetUsage):
|
||||
item = q.values_list('expected_result', flat=True).first()
|
||||
assert item == 10
|
||||
|
||||
class TestObjectsProperty(BaseQuerySetUsage):
|
||||
|
||||
def test_objects_property_returns_fresh_queryset(self):
|
||||
assert TestModel.objects._result_cache is None
|
||||
len(TestModel.objects) # evaluate queryset
|
||||
assert TestModel.objects._result_cache is None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user