擅长:python、mysql、java
<p>在读了雨果的回信后,我做了一些挖掘,并提出了有效的解决方案:</p>
<pre><code>class Category(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return '%s' % self.name
class Expense(models.Model):
category = models.ForeignKey(Category)
add_date = models.DateField()
amount = models.DecimalField(max_digits=10, decimal_places=2)
</code></pre>
<p>我不确定这是不是最优雅的解决方法,但效果很好。如果有更好的解决方法,请告诉我:)</p>