16👍
✅
It’s not possible to add tags
in update_or_create
because tags
is a ManyToManyField
and therefore involves an intermediate table for database queries.
You can however do it in two lines using get_or_create
:
user = Users.objects.get_or_create(name='test_user')
user.tags.add(tag_1)
0👍
user, created = Users.objects.get_or_create(name=’test_user’)
user.tags.add(tag_1)
get_or_create return tuple
- Can I get expiration time of specified key in django cache?
- How to start a long-running process from a Django view?
Source:stackexchange.com