extract an attribute django queryset code example
Example 1: how to save bulk create in django
# took 0.47 seconds
def builtin():
insert_list = []
for i in range(10000):
name="String number %s" %i
insert_list.append(Record(name=name))
Record.objects.bulk_create(insert_list)
Example 2: django q objects
from django.db.models import Q
obj, created = Person.objects.filter(
Q(first_name='Bob') | Q(first_name='Robert'),
).get_or_create(last_name='Marley', defaults={'first_name': 'Bob'})