Here is my code in Django:
class DeductRecord(models.Model):
userid = models.IntegerField()
total_amount = models.IntegerField()
type = models.IntegerField(choices=...)
class DeductHistoryA(models.Model):
deduct_record = ForeignKey(DeductRecord)
amount = models.IntegerField()
The code above is a function for deducting money. DeductRecord is to record total deduct amount, DeductHistory is to record deduct history every day.
DeductRecord have vary type, I could distinguish different DeductHistory type by foreign key deduct_record, but database would query twice if I want to know a DeductHistory instance's type.
Here is DeductHistoryB with type:
class DeductHistoryB(models.Model):
deduct_record = ForeignKey(DeductRecord)
amount = models.IntegerField()
type = models.IntegerField(choices=...)
I can know DeductHistory's type without query twice, but I should guarantee the type between DeductHistory and DeductRecord. I want to know, which is the best way if I want to distinguish different DeductHistory's type.
Aucun commentaire:
Enregistrer un commentaire