0

Actually I need suggestion about best practice to handle guest checkout and customer checkout. I have a scenario that 1 order can have multipul products (which is not problem). My order table is like

class Orders(models.Model):
    customer= models.ForeignKey(Customer, on_delete=models.CASCADE)
    order_number = models.AutoField(primary_key=True)
    total_amount = models.DecimalField(max_digits=10, decimal_places=2)
    ordertime = models.DateTimeField(auto_now_add=True)
    order_status = models.CharField(max_length=50)
    is_placed = models.BooleanField(default=False)

and then it is linked to product table like this

class OrderProduct(models.Model):
    order=models.ForeignKey(Orders, on_delete=models.CASCADE)
    activity = models.ForeignKey(ActivityOrganizer, on_delete=models.CASCADE)
    participants=models.IntegerField(default=0)
    totalPrice=models.DecimalField(max_digits=10, decimal_places=2)
    checkIn = models.DateField()
    language = models.CharField(max_length=50, null=False, blank=False)

And my Customer Table is

class Customer(models.Model):
    customerProfile = models.OneToOneField(User, on_delete=models.CASCADE)
    first_name=models.CharField(max_length=50, null=False, blank=False)
    last_name=models.CharField(max_length=50, null=False, blank=False)
    email=models.CharField(max_length=50, null=False, blank=False)
    mobile_number=models.CharField(max_length=50, null=False, blank=False)
    profile_image=models.ImageField(null=True, upload_to='CustomerProfile')
    is_customer=models.BooleanField(default=False)
    city=models.CharField(max_length=50, null=True, blank=True)
    gender=models.CharField(max_length=50, null=True, blank=True)
    verification_key = models.CharField(max_length=100, null=True, blank=True)

Now I want to Enable guest checkouts aswell . then Should I use existing tables of order by allowing Foregin key Null ? Or I should make seprate order tables for this ? What will be best way ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.