gpt4 book ai didi

django - 无法解析 : type object 'Member' has no attribute '_default_manager, django 1.10

转载 作者:行者123 更新时间:2023-12-04 21:07:32 25 4
gpt4 key购买 nike

我有以下问题:
当我尝试通过模板从我的数据库中删除成员时,我收到以下错误:

类型对象 'Member' 没有属性 '_default_manager

我不确定我做错了什么,因为一切似乎都尽可能正常。
下面是我的问题的模型、 View 和模板片段。

GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)


class Member(models.Model):
"""Model for a member"""
surname = models.CharField(max_length=255)
names = models.CharField(max_length=255)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
dob = models.DateField()
# anniversary = models.ForeignKey(Anniversary)
email = models.EmailField()
phone = PhoneNumberField(help_text='Please, use this format +3232')
address = models.CharField(max_length=255)
suburb = models.CharField(max_length=255, choices=Suburbs_list, default=Suburbs_list[0][0])
province = models.CharField(max_length=255, choices=Provinces_List, default=Provinces_List[8][1])
country = models.CharField(max_length=255, default='Unite Kingdom')
previous_church = models.CharField(max_length=255)
added_date = models.DateField(default=datetime.date.today)

def __str__(self):
return self.surname

class Meta:
ordering = ['-suburb', 'province']

我的删除 View :
class DeleteMember(LoginRequiredMixin, generic.DeleteView):
"""
This view will be responsible of deleting an member
"""
model = Member
template_name = 'members/delete_member.html'
success_url = reverse_lazy('website:home')

和我的表格:
class MemberForm(forms.ModelForm):
dob = forms.DateField(widget=extras.SelectDateWidget, label='Date of Birth')
phone = forms.CharField(label='Phone Number',
widget=forms.TextInput(attrs={'placeholder': '+41524242424'}))

class Meta:
model = Member
exclude = ['added_date']
error_messages = {
'phone': {
'max_length': _("Please use this format +41524242424 ."),
}
}

和我的删除网址:
url(r'^delete-member/(?P<pk>\d+)/delete/$', DeleteMember.as_view(),
name='delete_member'),

并在模板中:
<a class="btn btn-danger btn-edit" role="button" href="{% url "website:delete_member" pk=member.id %}">Delete</a>

我的追溯:
Internal Server Error: /delete-member/1/delete/
Traceback (most recent call last):
File "/project/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/project/lib/python3.5/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/project/lib/python3.5/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/project/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/project/lib/python3.5/site-packages/django/contrib/auth/mixins.py", line 56, in dispatch
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
File "/project/lib/python3.5/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/project/lib/python3.5/site-packages/django/views/generic/detail.py", line 115, in get
self.object = self.get_object()
File "/project/lib/python3.5/site-packages/django/views/generic/detail.py", line 32, in get_object
queryset = self.get_queryset()
File "/project/lib/python3.5/site-packages/django/views/generic/detail.py", line 68, in get_queryset
return self.model._default_manager.all()
AttributeError: type object 'Member' has no attribute '_default_manager'

我将不胜感激任何帮助。

最佳答案

我发现了这个问题,出于某种原因,因为我也调用了我的模型成员和 View 成员,它是有冲突的。所以我只是重命名了 View 。

关于django - 无法解析 : type object 'Member' has no attribute '_default_manager, django 1.10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41909938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com