无法解析:类型对象’Member’没有属性’_default_manager,django 1.10

我有以下问题:

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

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

我不确定我做错了什么,因为一切似乎都尽可能正常.
贝娄是我的问题的模型,视图和模板片段.

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']

我的删除视图:

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'

我将不胜感激任何帮助.

最佳答案 我找到了这个问题,出于某些原因,因为我已经打电话给我的模特会员和我的观点会员,但这是冲突的.所以我只是重命名了视图.

点赞