Hi Every one! I 'm looking for help.

I'm working with  a multi vendor website using django. But there is an
issue that I have vendor object vendor but it says User has no vendor. Why
is this happening and how may I solve this?

*MY model*

from django.contrib.auth.models import Userfrom django.db import
models*class Vendor*(models.Model):
    name = models.CharField(max_length=255)
    created_at = models.DateTimeField(auto_now_add=True)
    created_by = models.OneToOneField(User, related_name='vendor',
on_delete=models.CASCADE)
class Meta:
    ordering = ['name']

def __str__(self):
    return self.name

*My View*
*def become_vendor(request)*:
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            vendor = Vendor.objects.create(name=user.username, created_by=user)
            return redirect('frontpage')

    else:
        form = UserCreationForm()
    return render(request, 'vendor/become_vendor.html', {'form': form})
@login_requireddef vendor_admin(request):
    vendor = request.user.vendor
    return render(request, 'vendor/vendor_admin.html', {'vendor': vendor})

*Error i'm getting*
RelatedObjectDoesNotExist at /maduka/vendor_admin/

User has no vendor.

Request Method: GET
Request URL: http://127.0.0.1:8000/maduka/vendor_admin/
Django Version: 3.1.3
Exception Type: RelatedObjectDoesNotExist
Exception Value:

User has no vendor.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKjP07mdfQgHL_hTsXRuUzGTveJJG9VFbTOxQ7ma7DviSCnGaA%40mail.gmail.com.

Reply via email to