vittoriozamboni / django-groups-manager

Manage django groups collection based on django-mptt.
MIT License
96 stars 23 forks source link

How do I add a password to the member I added? #39

Closed trueman61 closed 4 years ago

trueman61 commented 4 years ago

We can create fields such as username, e-mail. However, the password field is not available. When I add a member to the member add page, I want to set the password on the page. How can I do it?

forms.py

class CalisanForm(forms.ModelForm):
    member = forms.CharField(max_length=100, label='Çalışan Adı')

    class Meta:
        model = User
        fields = [
            'member',
        ]

views.py

def calisan(request):
    form = CalisanForm(request.POST or None)
    if form.is_valid():
        member = form.cleaned_data['member']
        member = Member.objects.create(first_name=member)
        return redirect('home')
    return render(request, 'accounts/calisan/calisan.html', {'form': form})
vittoriozamboni commented 4 years ago

Hi! To add the password to the newly created user you need to access to the Django user, as the Member model does not hold this information. To access the user, you can use the django_user method: member = Member.objects.create(first_name=member) member.django_user.set_password(“password”)

trueman61 commented 4 years ago

Thank you so much.