Im working on a Django project where i was using postgres and it was working fine. Now i want to use MongoDB but im getting "No exception message supplied" error most of times when querying on objects. please find the below codes for reference and help.
Model
class Order(models.Model):
order_status = (('Pending', 'Pending'), ('Under Process', 'Under Process'), ('Dispatched',
'Dispatched'),
('Delivered', 'Delivered'), ('Cancelled', 'Cancelled'), ('Out for
delivery',
'Out for delivery'))
patient = models.ForeignKey(Patient, on_delete=models.SET_NULL, null=True, blank=True)
shipping_address = models.ForeignKey(ShippingAddress, on_delete=models.DO_NOTHING,
null=True,
blank=True)
order_created = models.DateTimeField(auto_now_add=True,null=True)
date_ordered = models.DateTimeField(null=True)
complete = models.BooleanField(default=False)
transaction_id = models.CharField(max_length=100, null=True)
order_number = models.CharField(max_length=20, unique=True, null=True)
status = models.CharField(choices=order_status, default='Pending', max_length=30)
payment_status = models.CharField(choices=(('Received', 'Received'), ('Failed', 'Failed'),
('Pending', 'Pending')),
default='Pending', max_length=30)
ip_address = models.CharField(max_length=30, null=True)
coupon_applied = models.BooleanField(null=True,blank=True)
coupon =
models.ForeignKey(ShoppingCoupon,on_delete=models.DO_NOTHING,null=True,blank=True)
coupon_discount = models.DecimalField(max_digits=7,decimal_places=2,
null=True,blank=True,default=0)
# Payment details captured from payment gateway
payment_order_id = models.CharField(max_length=100, null=True) # razorpay order id
payment_id = models.CharField(max_length=100, null=True) # Razorpay payment id
payment_signature = models.CharField(max_length=100, null=True)
payment_method = models.CharField(max_length=100, null=True)
ordered_medicine = models.JSONField(null=True,blank=True)
Query
def cartData(request):
if request.user.is_authenticated and request.user.user_type == 'patient':
patient = Patient.objects.select_related('user').get(user=request.user)
order, created = Order.objects.get_or_create(patient=patient, complete=False) // Im
getting error here
items = order.cartitem_set.select_related('medicine').all()
cartItems = order.get_cart_items
im getting error on "order, created = Order.objects.get_or_create(patient=patient, complete=False)"
try exceptbloc to achieve this goal too :try: order = Order.objects.get(patient=patient, complete=False) except: Order.DoesNotExist as e: print(e.message) order = Order(patient=patient, complete=False) order.save()ValueError?TypeError? try to catch it in the except block too