When working with django, it was necessary to write a script to populate the database for further testing.
There is a table in which it is necessary to refer to another (previously filled) table, for this I remove all id records from the filled table using the function:
def listId(Entity): list_id = Entity.objects.values_list('id') if not list_id: exit(0) return list_id Where Entity is an entity (model) corresponding to this table, but when list_id is displayed on the screen:
QuerySet [(10919745,), (10919746,), (10919747,), (10919748,), (10919749,), (10919750,), (10919751,), (10919752,), (10919753,), (10919754, )]
This affects 2 questions:
- Why are there such strange
idin the table?
data generation for this table goes to functions:
def generateWModel(N): print("\nWModel\n") roll = [] personal = e.Personal('is') for i in range(int(N)): roll.append(WModel( wname = personal.name(gender = 'male') )) print(roll[i - 1]) return roll and is entered into the table by the function:
def commit(data, Entity): try: mess = Entity.objects.bulk_create(data) print(mess) except Exception as ex: print(ex) return At the moment there are no more than 50 records
- Why the
list_idelementlist_idso weird, with a comma at the end
10919745,