在 Django 电子商务开发中是否有可能拥有 Profile 模型和 Customer 模型?

Is the any possibility of having a Profile model and Customer model in Django e-commerce development?

我想知道将这两个模型与 Order、OrderItem 等其他模型一起使用的可能性

我试过 运行 它就像我的 models.py

class Profile(models.Model):
    user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
    name = models.CharField(max_length=30, null=True, blank=True, help_text="Insert your name")
    image = models.ImageField(default='default.png', upload_to='profile_pics')

class Customer(models.Model):
    name = models.OneToOneField(Profile, on_delete=models.CASCADE)
    phone = models.CharField(max_length=11, null=True, blank=True)
    address = models.CharField(max_length=20, null=True, blank=True)
    phone = models.CharField(max_length=11, null=True, blank=True)
    address = models.CharField(max_length=20, null=True, blank=True)

class Order(models.Model):
    customer = models.ForeignKey(Customer, on_delete=models.CASCADE, null=True, blank=True)
    complete = models.BooleanField(default=False, null=True, blank=True)
    date_ordered = models.DateTimeField(auto_now_add=True)
    transaction_id = models.CharField(max_length=100, null=True)

有没有像上面这样的模型?

如果是,

如何在 views.py 中显示它以验证用户(配置文件)并同时创建客户。

我认为您的上述模型结构可能运行良好,但在 views.py 中您可以使用令牌身份验证,并且在创建客户时您可以进行身份​​验证 用户是否存在。

更多您可以在视图中使用 user = request.user 然后

profile = Profile.objects.get(user__id=user)
if profile:
 .............
 create your customer here