【问题标题】:How to store each months data in django model如何在 Django 模型中存储每个月的数据
【发布时间】:2022-01-11 03:47:23
【问题描述】:

我正在创建一个应用程序,人们可以在其中登录并创建委员会并邀请其他用户加入他们的委员会,然后加入该委员会的人将每月支付委员会费用,直到结束日期。并且其中一位用户将在每个月底获得委员会,我遇到了一个问题,我不知道如何存储按月付费的用户的数据。我已经创建了所有这些 django 模型。但是现在缺少的部分是存储每个月的数据,以便我可以将状态显示为待处理或已完成。

class Committee(models.Model):
    committee_creator = models.ForeignKey(Profile, on_delete=models.CASCADE)
    committee_name = models.CharField(max_length=100)
    committee_members_limit = models.IntegerField()
    committee_amount_per_month = models.IntegerField(default=0)
    committee_month_period = models.IntegerField(default=0)
    committee_amount_limit = models.IntegerField(null=True)
    committee_starting_date = models.DateTimeField(auto_now_add=False)
    committee_ending_date = models.DateTimeField(auto_now_add=False)
class Participants(models.Model):
    participants_name = models.ForeignKey(Profile, on_delete=models.CASCADE)
    participants_committee_name = models.ForeignKey(Committee, on_delete=models.CASCADE)
    participants_paid_status = models.BooleanField(default=False)
    participants_amount_paid = models.IntegerField()
    participants_payment_slip = models.ImageField(upload_to='images/', null=True, blank=True)

【问题讨论】:

    标签: python sql django database


    【解决方案1】:

    您可以再创建一张名为 PaymentDetails 的表格,其中包含如下付款日期详细信息

    class Participants(models.Model):
        participants_name = models.ForeignKey(Profile, on_delete=models.CASCADE)
        participants_committee_name = models.ForeignKey(Committee, on_delete=models.CASCADE)
    
    class PaymentDetails (models.Model):
        participants_name = models.ForeignKey(Participants, on_delete=models.CASCADE)
        participants_paid_status = models.BooleanField(default=False)
        participants_amount_paid = models.IntegerField()
        participants_payment_date = models.DateTimeField(auto_now_add=True)
        participants_payment_slip = models.ImageField(upload_to='images/', null=True, blank=True)
    

    现在,您可以获得参与者每月的付款明细。

    【讨论】:

    • 非常感谢,我将实施它
    猜你喜欢
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多