Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在django python中通过model.py插入db吗_Python_Django_Web_Model - Fatal编程技术网

我可以在django python中通过model.py插入db吗

我可以在django python中通过model.py插入db吗,python,django,web,model,Python,Django,Web,Model,我可以通过django中的model.py插入数据吗 model.py: class details(models.Model): team_id = models.AutoField(primary_key = True) gbu_id = models.IntegerField() team_name = models.CharField(max_length=48) team_desc = models.TextField() updated_

我可以通过django中的
model.py
插入数据吗

model.py

class details(models.Model):

    team_id = models.AutoField(primary_key = True)
    gbu_id =  models.IntegerField()
    team_name =  models.CharField(max_length=48)
    team_desc = models.TextField()
    updated_time = models.DateTimeField(default=datetime.datetime.now())
    status = models.IntegerField(default=1)



    @staticmethod
    def add_team_details():
        details_obj = details()
        details_obj.gbu_id = "2"
        details_obj.team_name = "FTO"
        details_obj.team_desc = "test data"
        details_obj.save()

        return "Success"

为了这些目的,请改用。

我不知道,你为什么要这样做。但它应该可以工作。它不工作。我可以使用@classmethod def add_team_details(self):self.gbu_id=“2”self.team_name=“FTO”self.team_desc=“test data”self.save()吗