Monday, September 21, 2020

Re: How to Add to Django Administration Using Code

do want to add the picture file to the customer application or want to see the picture in admin?

On Sunday, September 20, 2020 at 11:35:05 AM UTC-4 Lightning Bit wrote:
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/91e61ad8-1a47-4b73-b0cf-7053056e6a21n%40googlegroups.com.

No comments:

Post a Comment