Django – 如何解决添加成员的问题?

huangapple go评论67阅读模式
英文:

Django - How do I solve the problem of adding members?

问题

我正在使用 django-groups-manager

有一个成员部分。我在录制时遇到错误。我可能漏掉了什么或犯了错误。可能出现在哪里?

> 在 /accounts/register/ 上的 TypeError
>
> Member() 收到了一个意外的关键字参数 'name'

views.py

from groups_manager.models import Group, GroupType, Member

def register_view(request):
    form = RegisterForm(request.POST or None)
    if form.is_valid():
        user = form.save()
        new_group_name = form.cleaned_data['new_group_name']
        new_group, created = Group.objects.update_or_create(name=new_group_name)
        user.groups.add(AGroup.objects.get(name=new_group_name))
        member = form.cleaned_data['member']
        member = Member.objects.create(name=member)
        user.save()
        password = form.cleaned_data.get('password1')
        new_user = authenticate(username=user.username, password=password)
        login(request, new_user)
        return redirect('home')
    return render(request, 'accounts/form.html', {'form': form, 'title': 'Üye Ol'})

有问题的这一行:

member = Member.objects.create(name=member)
英文:

I'm using django-groups-manager.

There is a member section. I get an error while recording. I'm missing or making mistakes. Where could it be?

> TypeError at /accounts/register/
>
> Member() got an unexpected keyword argument 'name'

views.py

from groups_manager.models import Group, GroupType, Member

def register_view(request):
    form = RegisterForm(request.POST or None)
    if form.is_valid():
        user = form.save()
        new_group_name = form.cleaned_data['new_group_name']
        new_group, created = Group.objects.update_or_create(name=new_group_name)
        user.groups.add(AGroup.objects.get(name=new_group_name))
        member = form.cleaned_data['member']
        member = Member.objects.create(name=member)
        user.save()
        password = form.cleaned_data.get('password1')
        new_user = authenticate(username=user.username, password=password)
        login(request, new_user)
        return redirect('home')
    return render(request, 'accounts/form.html', {'form': form, 'title': 'Üye Ol'})

This line problematic:

member = Member.objects.create(name=member)

答案1

得分: 2

使用 first_name,Member 模型中没有 name 参数。

member = Member.objects.create(first_name=member)
英文:

Use first_name, there is no name parameter in Member model

member = Member.objects.create(first_name = member)

huangapple
  • 本文由 发表于 2020年1月4日 01:21:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定