且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何测试Django模型的形式?

更新时间:2023-11-29 15:13:10

仅创建模型对象不会在数据库中创建记录.

Simply creating model object will not create the record in the database.

使用 .objects.create 创建记录.

test_filter = Filter.objects.create(
    user_profile_id= 3,
    keyword = 'ca',
    industry = 'it',
    zip_code = '50002',
    distance = 30,
    creation_date = datetime.date.today(),
    last_run_date = datetime.date.today()
)

或使用保存:

test_filter = Filter(...)
test_filter.save()