mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-17 04:10:24 +00:00
Fixed issue #6, bug with InheritanceManager and descriptor fields (e.g. FileField).
Thanks zyegfryed for the fix and sayane for tests.
This commit is contained in:
commit
e418cc909a
3 changed files with 22 additions and 4 deletions
|
|
@ -7,6 +7,9 @@ tip (unreleased)
|
|||
0.6.0 (2011.02.18)
|
||||
------------------
|
||||
|
||||
- Fixed issue #6, bug with InheritanceManager and descriptor fields (e.g.
|
||||
FileField). Thanks zyegfryed for the fix and sayane for tests.
|
||||
|
||||
- updated SplitField to define get_prep_value rather than get_db_prep_value.
|
||||
This avoids deprecation warnings on Django trunk/1.3, but makes SplitField
|
||||
incompatible with Django versions prior to 1.2.
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ from types import ClassType
|
|||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.db.models.fields.related import SingleRelatedObjectDescriptor
|
||||
from django.db.models.fields.related import OneToOneField
|
||||
from django.db.models.manager import Manager
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
class InheritanceQuerySet(QuerySet):
|
||||
def select_subclasses(self, *subclasses):
|
||||
if not subclasses:
|
||||
subclasses = [o for o in dir(self.model)
|
||||
if isinstance(getattr(self.model, o), SingleRelatedObjectDescriptor)
|
||||
and issubclass(getattr(self.model,o).related.model, self.model)]
|
||||
subclasses = [rel.var_name for rel in self.model._meta.get_all_related_objects()
|
||||
if isinstance(rel.field, OneToOneField)
|
||||
and issubclass(rel.field.model, self.model)]
|
||||
new_qs = self.select_related(*subclasses)
|
||||
new_qs.subclasses = subclasses
|
||||
return new_qs
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from datetime import datetime
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
|
@ -7,21 +8,35 @@ from model_utils.fields import SplitField, MonitorField
|
|||
from model_utils import Choices
|
||||
|
||||
class InheritParent(InheritanceCastModel):
|
||||
non_related_field_using_descriptor = models.FileField(upload_to='test')
|
||||
normal_field = models.TextField()
|
||||
pass
|
||||
|
||||
class InheritChild(InheritParent):
|
||||
non_related_field_using_descriptor_2 = models.FileField(upload_to='test')
|
||||
normal_field_2 = models.TextField()
|
||||
pass
|
||||
|
||||
class InheritChild2(InheritParent):
|
||||
non_related_field_using_descriptor_3 = models.FileField(upload_to='test')
|
||||
normal_field_3 = models.TextField()
|
||||
pass
|
||||
|
||||
class InheritanceManagerTestParent(models.Model):
|
||||
# test for #6
|
||||
# I'm using FileField, because it will always use descriptor
|
||||
non_related_field_using_descriptor = models.FileField(upload_to='test')
|
||||
normal_field = models.TextField()
|
||||
objects = InheritanceManager()
|
||||
|
||||
class InheritanceManagerTestChild1(InheritanceManagerTestParent):
|
||||
non_related_field_using_descriptor_2 = models.FileField(upload_to='test')
|
||||
normal_field_2 = models.TextField()
|
||||
pass
|
||||
|
||||
class InheritanceManagerTestChild2(InheritanceManagerTestParent):
|
||||
non_related_field_using_descriptor_2 = models.FileField(upload_to='test')
|
||||
normal_field_2 = models.TextField()
|
||||
pass
|
||||
|
||||
class TimeStamp(TimeStampedModel):
|
||||
|
|
|
|||
Loading…
Reference in a new issue