Sunday, September 20, 2020

How to Add to Django Administration Using Code

Hi all, 

I am trying to figure out how to add "Customers" using code. Please look at the administration layout: 

HELP.png

I was able to add to "Groups" using the following code in "views.py": 

@unauthenticated_user
def registerPage(request):

            form = CreateUserForm()

            if request.method == 'POST':
                form = CreateUserForm(request.POST)
                if form.is_valid():
                    user = form.save()
                    username = form.cleaned_data.get('username')
                    
                    group = Group.objects.get(name='customer')
                    user.groups.add(group)
                    


                    messages.success(request, 'BOLT Force account was created for' + username )
                    return redirect('login')

            data= cartData(request)

            items=data['items']
            order=data['order']
            cartItems=data['cartItems']

            products = Product.objects.all()
            context = {'products':products, 'items':items, 'order':order, 'cartItems':cartItems, 'form':form}
            return render(request, 'store/register.html', context)

However, I am unsure of how to add to the "Customers" section of the picture above. I have tried almost every technique with no luck. I wanted both the "Groups" and the "Customers" to have the same registered person added at once. Would anyone happen to know how to fix this? 

Thank you!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f26749b-7c0f-4f50-970e-892e2f5cb2cfn%40googlegroups.com.

No comments:

Post a Comment