我正在尝试为我的应用程序使用django过滤器,但是它总是返回相同的错误。
from django.contrib.auth.models import Promoters
ImportError: cannot import name 'Promoters' from 'django.contrib.auth.models' (C:\Users\tymot\Desktop\my_app\env\lib\site-packages\django\contrib\auth\models.py)
有人有类似的问题吗?如何最好地解决呢? Django versia的变化? 还是有其他选择?
我的Django版本(2,1,2,'final',0),Python 3.6。
编辑: 我正在尝试将搜索引擎添加到我的网站,然后我安装了“ pip install django-filter”并将其添加到我的settings.py中。接下来,我创建了filters.py:
from django.contrib.auth.models import Promoters
import django_filters
class PromotersFilter(django_filters.FilterSet):
class Meta:
model = Promoters
fields = ['age', 'profession', 'sex', 'city']
对于我的models.py
class Promoters(models.Model):
MEAN = 'M'
WOMAN = 'W'
SEX = (
(MEAN, 'Mean'),
(WOMAN, 'Woman'),
)
name = models.CharField(max_length=50)
surname = models.CharField(max_length=50)
photo = models.FileField(null=True, blank=True)
age = models.IntegerField(validators=[MinValueValidator(0),
MaxValueValidator(99)])
profession = models.CharField(max_length=50)
sex = models.CharField(max_length=1, choices=SEX, default=MEAN)
city = models.CharField(max_length=50)
hobby = models.CharField(max_length=50)
number_friends = models.IntegerField(validators=[MinValueValidator(0)])
related_brands = models.IntegerField(validators=[MinValueValidator(0),
MaxValueValidator(10)])
user_group = models.CharField(max_length=200)
activities_month = models.IntegerField()
fb_links = models.CharField(max_length=200)
并创建一个views.py
def Promotors(request):
#promoters
campaignlist = Campaign.objects.filter(customer_name=request.user)
promoters_list = Promoters.objects.all()
#search rama
promoters_filter = PromotersFilter(request.GET, queryser=promoters_list)
#context
context = { 'campaignlist':campaignlist, 'filter':promoters_filter}
return render(request, 'account/costumer_profile.html', context)
然后,当我尝试启动服务器时,出现错误:'ImportError:...'
在其他论坛上,有信息表明这可能是由于django-filters与django版本不匹配所致。 但是我没有找到有关如何解决此问题以实施搜索引擎的任何信息。