Py学习  »  Django

如何在django中保存一些数据而不将其添加到表单中?

Jack022 • 7 年前 • 2070 次点击  

我有一个这样的模型:

class MyModel(models.Model):
    rate = models.CharField(max_length=100)
    amount = models.FloatField()
    userid = models.CharField(max_length=100)
    date = models.CharField() //This should be used to save the date

    def save(self): # ALL the signature

        super(MyModel, self).save()

一种形式:

class MyForm(forms.ModelForm):

    rate = forms.CharField()
    amount = forms.FloatField()


    class Meta:
        model = MyModel
        fields = ("rate", "amount")

    def save(self, commit=True):
        send = super(MyForm, self).save(commit=False)
        if commit:
            send.save()
        return send

目前,我的表单正在保存字段 rate 和 amount 在我的数据库中,一旦用户使用表单。我想节省我的数据库 user 提交表单的人、保存表单的日期/时间以及用户不能提交但“自动”保存的某些其他数据。在Django我该怎么做?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40902
文章 [ 1 ]  |  最新文章 7 年前