开发者

Django Non-Rel: QuerySet is always empty, even though objects exist

filter() and all() not 开发者_开发问答working on 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')
[]
>>> 

On the following model:

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 like filter() and all() on Django-Nonrel keep returning empty, even though objects exists in the database. get() works fine.

I've also tried removing the meta attributes, but to no avail.


The problem is that class Meta: ordering = ['menu','parent','weight']. This results in "INNER JOIN" statement that django-norel does not support it or implement it yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜