users/views.py
def profile(request):
    '''
    view function for a user profile
    '''

    if request.method=='POST':
        user_form=UserUpdateForm(request.POST,instance=request.user)
        profile_form=ProfileUpdateForm(request.POST,request.FILES,instance=request.user.profile)
        hood_form=AddNeighbourhoodForm(request.POST,instance=request.user.profile.neighbourhood)
        biz_form=BusinessForm(request.POST,instance=request.user)

        if user_form.is_valid() and profile_form.is_valid() and biz_form.is_valid():
            user_form.save()
            profile_form.save()
            hood_form.save()

            biz=biz_form(commit=False)
            biz.owner=request.user
            biz.hood=request.user.profile.neighbourhood
            biz.save()

            messages.success(request,f'Details have been updated')

            return redirect('profile')

    else:
        user_form=UserUpdateForm(instance=request.user)
        profile_form=ProfileUpdateForm(instance=request.user.profile)
        hood_form=AddNeighbourhoodForm(instance=request.user.profile.neighbourhood)
        biz_form=BusinessForm(request.POST,instance=request.user)
        # loc_form=AddLocationForm(request.POST,instance=request.user.profile.location)

    user=User.objects.get(pk=request.user.id)
    posts=user.post_set.all()

    context={
        'usr_form':user_form,
        'prof_form':profile_form,
        'hood_form':hood_form,
        'biz_form':biz_form,
        'post':posts
    }    



    return render(request,'users/profile.html',context)

    view function for a user profile
    
view function for a user profile
view function for a user profile
def profile(request):
    if request.method=='POST':
        user_form=UserUpdateForm(request.POST,instance=request.user)
        profile_form=ProfileUpdateForm(request.POST,request.FILES,instance=request.user.profile)
        hood_form=AddNeighbourhoodForm(request.POST,instance=request.user.profile.neighbourhood)
        biz_form=BusinessForm(request.POST,instance=request.user)
        if user_form.is_valid() and profile_form.is_valid() and biz_form.is_valid():
            user_form.save()
            profile_form.save()
            hood_form.save()
            biz=biz_form(commit=False)
            biz.owner=request.user
            biz.hood=request.user.profile.neighbourhood
            biz.save()
            messages.success(request,f'Details have been updated')
            return redirect('profile')
    else:
        user_form=UserUpdateForm(instance=request.user)
        profile_form=ProfileUpdateForm(instance=request.user.profile)
        hood_form=AddNeighbourhoodForm(instance=request.user.profile.neighbourhood)
        biz_form=BusinessForm(request.POST,instance=request.user)
    user=User.objects.get(pk=request.user.id)
    posts=user.post_set.all()
    context={
        'usr_form':user_form,
        'prof_form':profile_form,
        'hood_form':hood_form,
        'biz_form':biz_form,
        'post':posts
    }    
    return render(request,'users/profile.html',context)
def profile ( request ) : if request . method == 'POST' : user_form = UserUpdateForm ( request . POST , instance = request . user ) profile_form = ProfileUpdateForm ( request . POST , request . FILES , instance = request . user . profile ) hood_form = AddNeighbourhoodForm ( request . POST , instance = request . user . profile . neighbourhood ) biz_form = BusinessForm ( request . POST , instance = request . user ) if user_form . is_valid ( ) and profile_form . is_valid ( ) and biz_form . is_valid ( ) : user_form . save ( ) profile_form . save ( ) hood_form . save ( ) biz = biz_form ( commit = False ) biz . owner = request . user biz . hood = request . user . profile . neighbourhood biz . save ( ) messages . success ( request , f'Details have been updated' ) return redirect ( 'profile' ) else : user_form = UserUpdateForm ( instance = request . user ) profile_form = ProfileUpdateForm ( instance = request . user . profile ) hood_form = AddNeighbourhoodForm ( instance = request . user . profile . neighbourhood ) biz_form = BusinessForm ( request . POST , instance = request . user ) user = User . objects . get ( pk = request . user . id ) posts = user . post_set . all ( ) context = { 'usr_form' : user_form , 'prof_form' : profile_form , 'hood_form' : hood_form , 'biz_form' : biz_form , 'post' : posts } return render ( request , 'users/profile.html' , context )
view function for a user profile
view function for a user profile
'''
    view function for a user profile
    ''' # loc_form=AddLocationForm(request.POST,instance=request.user.profile.location)
request