'FavoriteManager'对象没有属性'get_query_set' [英] 'FavoriteManager' object has no attribute 'get_query_set'

查看:168
本文介绍了'FavoriteManager'对象没有属性'get_query_set'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://bitbucket.org/last_partizan/django-收藏夹/概述,并且我设置了所有权利,当我运行它给我的代码'FavoriteManager'对象没有属性'get_query_set 。错误是从这条线上的django-favorites models.py 发生的错误

I'm using django-favorites from https://bitbucket.org/last_partizan/django-favorites/overview, and I set everything right and when I run the code it gave me 'FavoriteManager' object has no attribute 'get_query_set'. The error was occuring from the django-favorites models.py from this line

qs = self.get_query_set().filter(content_type=content_type, object_id=obj.pk)



fav按钮为所有我的发布,所以我需要更改 obj 发布。但即使改变后,我也会遇到同样的错误。这是怎么回事?

So I thought, I need to specify object. So I'm trying to use fav button for all my Post, so I need to change obj to Post. But even after changing I get same error. What is going on with this?

这是最喜欢的应用程序中的 models.py

$ b

This is models.py inside favorite app, where error is occurring

def favorites_for_object(self, obj, user=None):
       """ Returns Favorites for a specific object """
       content_type = ContentType.objects.get_for_model(type(obj))
       qs = self.get_query_set().filter(content_type=content_type, 
                                         object_id=obj.pk)
       if user:
           qs = qs.filter(user=user)

       return qs

这是我正在调用的地方fav_item

This is where I'm calling fav_item

<div class="actions">{% fav_item post user %}</div>

说我想把fav_item放在我的类别模型上

Lets say I want to put fav_item on my category model

class Category(models.Model): 
    name = models.CharField(max_length=128, unique=True)
    slug = models.CharField(max_length=100, unique=True)
    author = models.OneToOneField(settings.AUTH_USER_MODEL, unique=True)
    def save(self, *args, **kwargs):
        self.slug = uuslug(self.name,instance=self, max_length=100)
        super(Category, self).save(*args, **kwargs)

    def __unicode__(self): 
        return self.name

然后不要输入
main.models import类别
并将obj切换到类别。不幸的是,这里没有太多的文档: https://bitbucket.org/last_partizan/django-favorites/overview

Then doesn't it make sense to import main.models import Category and switch obj to Category. Unfortunately there's not much documentation here: https://bitbucket.org/last_partizan/django-favorites/overview

推荐答案

此问题与Django版本有关。方法 get_query_set 已从Django 1.8.x中删除。之前,该方法由 RenameManagerMethods 使用。检查此github源: https: //github.com/django/django/blob/stable/1.7.x/django/db/models/manager.py#L56

This problem is related to Django version. The method get_query_set has been removed from Django 1.8.x . Before that, this method was used by RenameManagerMethods. Check this github source: https://github.com/django/django/blob/stable/1.7.x/django/db/models/manager.py#L56

另外 django-favorites 于2013年上次更新,从源码可以看出。您应该考虑降级Django版本。

Also django-favorites was last updated in 2013, as I can see from the source. You should consider downgrading your Django version.

这篇关于'FavoriteManager'对象没有属性'get_query_set'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆