Django Non-Rel: QuerySet всегда пуст, даже если объекты существуют - PullRequest
1 голос
/ 06 августа 2011

filter () и all () не работают на django-nonrel

>>> Item.objects.get(display_name='Test Item')
<Item: Test Item>
>>> Item.objects.all()
[]
>>> Item.objects.get(display_name='Test Item')
<Item: Test Item>
>>> Item.objects.filter(display_name='Test Item')
[]
>>> 

На следующей модели:

class Item(models.Model):
    item_id = models.AutoField(
        primary_key = True,
        db_column = 'id'
    )
    menu = models.ForeignKey(
        Menu,
        verbose_name = l('Menu'),
        related_name = 'items',
        db_column = 'menu_id'
    )
    display_name = models.NameField(
        db_column = 'display_name'
    )
    description = models.DescriptionField(
        db_column = 'description'
    )
    url = models.CharField(
        max_length = 255,
        verbose_name = l('Path'),
        db_column = 'url'
    )

    #/////////////////////////////////////////////////////////////////////
    #//// Flags
    #/////////////////////////////////////////////////////////////////////
    external = models.BooleanField(
        editable = False,
        default = False,
        db_column = 'external'
    )
    new_window = models.BooleanField(
        verbose_name = l('Open in new window'),
        default = False,
        db_column = 'new_window'
    )
    enabled = models.EnabledField(
        db_column = 'is_enabled'
    )
    expanded = models.BooleanField(
        verbose_name = l('Expanded by default'),
        editable = False, # Will be implemented in future versions.
        default = False,
        db_column = 'is_expanded'
        )
    collapsible = models.BooleanField(
        verbose_name = l('Collapsible'),
        help_text = l('If this item has children, indicates if they may be collapsed'),
        db_column = 'is_collapsible'
    )

    #/////////////////////////////////////////////////////////////////////
    #//// Item tree
    #/////////////////////////////////////////////////////////////////////
    parent = models.ForeignKey(
        'self',
        verbose_name = l('Parent'),
        related_name = 'children',
        blank = True,
        null = True,
        db_column = 'parent_id'
    )
    has_children = models.BooleanField(
        editable = False,
        default = False,
        db_column = 'has_children'
    )
    depth = models.PositiveIntegerField(
        editable = False,
        default = 1,
        db_column = 'depth'
    )
    weight = models.IntegerField(
        verbose_name = l('Weight'),
        default = 0,
        db_column = 'weight'
    )

    #/////////////////////////////////////////////////////////////////////
    #//// HTML properties
    #/////////////////////////////////////////////////////////////////////
    id = models.CharField(
        max_length = 255,
        verbose_name = l('Id'),
        help_text = l('By default, the rendered link id will be in the format [item.name]-[item.pk]. Use this field to override'),
        default = '',
        blank = True,
        db_column = 'link_id'
    )
    cls = models.CharField(
        max_length = 255,
        verbose_name = l('Class'),
        help_text = l('By default, the rendered link class will be in the format [menu.name]. Use this field to append extra classes.'),
        default = '',
        blank = True,
        db_column = 'class'
    )
    title = models.CharField(
        max_length = 255,
        verbose_name = l('Title'),
        help_text = l('By default, the rendered link title will be item.name. Use this field to override.'),
        default = '',
        blank = True,
        db_column = 'title'
    )
    target = models.CharField(
        max_length = 255,
        verbose_name = l('Target'),
        blank = True,
        default = '',
        db_column = 'target'        
    )
    rel = models.CharField(
        max_length = 255,
        verbose_name = l('Rel'),
        blank = True,
        default = '',
        db_column = 'rel'        
    )

class Meta:
        db_table = 'menu_item'
        verbose_name = l('Menu Item')
        verbose_name_plural = l('Menu Items')
        ordering = ['menu','parent','weight']

QuerySets, такие как filter () и all () в Django-Nonrel, продолжают возвращаться пустыми, даже если объекты существуют в базе данных. get () работает нормально.

Я также пытался удалить мета-атрибуты, но безрезультатно.

1 Ответ

0 голосов
/ 03 марта 2012

Проблема в том, что class Meta: ordering = ['menu','parent','weight']. Это приводит к выражению «INNER JOIN» о том, что django-norel пока не поддерживает и не реализует его.

...