Geek981108 最近的时间轴更新
Geek981108

Geek981108

V2EX 第 508441 号会员,加入于 2020-09-16 22:01:14 +08:00
Geek981108 最近回复了
2022-09-06 12:19:47 +08:00
回复了 tbg 创建的主题 MacBook Pro MacBook Pro 2019 16 寸能卖多少了?大佬估个价
相同配置, 现在挂着 1.43 待售
@ETONG 不行,直接设置 smb 的挂载权限 和 chmod 不太一样,在挂载时候指定就好了
mount -t cifs -o vers=3,rw,dir_mode=0777,file_mode=0777,username=xxx,password=xxx //10.0.1.1/xuyihe/xuyihe /xxx
把 xxx 换成自己的路径,指定没问题,同 truenas + ubuntu
2021-01-26 20:07:29 +08:00
回复了 Phishion 创建的主题 Django Django 更新一条可能不存在的特定数据是 Get 性能好还是 Filter 好
文档如是说:
update_or_create()
update_or_create(defaults=None, **kwargs)
A convenience method for updating an object with the given kwargs, creating a new one if necessary. The defaults is a dictionary of (field, value) pairs used to update the object. The values in defaults can be callables.

Returns a tuple of (object, created), where object is the created or updated object and created is a boolean specifying whether a new object was created.

The update_or_create method tries to fetch an object from database based on the given kwargs. If a match is found, it updates the fields passed in the defaults dictionary.

This is meant as a shortcut to boilerplatish code. For example:

defaults = {'first_name': 'Bob'}
try:
obj = Person.objects.get(first_name='John', last_name='Lennon')
for key, value in defaults.items():
setattr(obj, key, value)
obj.save()
except Person.DoesNotExist:
new_values = {'first_name': 'John', 'last_name': 'Lennon'}
new_values.update(defaults)
obj = Person(**new_values)
obj.save()
This pattern gets quite unwieldy as the number of fields in a model goes up. The above example can be rewritten using update_or_create() like so:

obj, created = Person.objects.update_or_create(
first_name='John', last_name='Lennon',
defaults={'first_name': 'Bob'},
)
For detailed description how names passed in kwargs are resolved see get_or_create().

As described above in get_or_create(), this method is prone to a race-condition which can result in multiple rows being inserted simultaneously if uniqueness is not enforced at the database level.

Like get_or_create() and create(), if you’re using manually specified primary keys and an object needs to be created but the key already exists in the database, an IntegrityError is raised.
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1677 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 16ms · UTC 16:32 · PVG 00:32 · LAX 08:32 · JFK 11:32
Developed with CodeLauncher
♥ Do have faith in what you're doing.