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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Python Django-保存前处理模型数据_Python_Django - Fatal编程技术网

Python Django-保存前处理模型数据

Python Django-保存前处理模型数据,python,django,Python,Django,我有一个django模型。我需要获取用户名和密码。但当时我想通过vk()类来处理它们,以获得uid,令牌,机密,并仅使用vk()类中的字段保存模型。我怎么做 from django.db import models from vk_class import vk class data(models.Model): # that's what I ask for username = models.CharField(max_length=50) password =

我有一个django模型。我需要获取
用户名
密码
。但当时我想通过
vk()
类来处理它们,以获得
uid
令牌
机密
,并仅使用
vk()
类中的字段保存模型。我怎么做

from django.db import models
from vk_class import vk

class data(models.Model):

    # that's what I ask for
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=50)

    # that's only what I want to save
    uid = vk(username=username, password=password).uid
    token = vk(username=username, password=password).token
    secret = vk(username=username, password=password).secret

评论后更新
您可以对此字段和自定义管理器使用
editable=False
来重载
对象。创建

然后在代码中

data_obj = data.objects.create(username, password)

instance.username
返回什么类型?我如何防止在数据库中写入
username
password
,并将
uid
用作django的
id
?@sardorbek为什么要复制用户名和密码字段,因为django Auth已经为您做了这件事@AbijithMg为什么我需要存储用户凭证,当我可以获取无条件令牌来访问VKAPI并使用它时?@AbijithMg首先在django中没有
Auth
模型,也许你的意思是
user
,但OP没有提供任何关于这与默认
user
模型相关的信息。这就是为什么我没有提出这样的建议。@Бчгзззззззззззззззз107?
data_obj = data.objects.create(username, password)