try:
context['id_customer'] = Customer.objects.get(user=self.request.user)
except:
context['id_customer'] = ''
return context
context['id_customer'] = Customer.objects.get(user=self.request.user)
if not AnonymousUser:
context['id_customer'] = Customer.objects.get(user=self.request.user)
else:
context['id_customer'] = ''
return context
Customer.objects.get(user=self.request.user)
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('api-auth', include('rest_framework.urls')),
path('', include('Pay.urls')),
]
if not settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
@receiver(post_save, sender=User)
def created_user_profile(sender, instance, created, **kwargs):
if created:
Customer.objects.create(user=instance)
@receiver
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()