Найти - Пользователи
Полная версия: Django ORM: узнать id только что добавленной записи в БД.
Начало » Django » Django ORM: узнать id только что добавленной записи в БД.
1
quadright
Сабж.
Singularity
https://docs.djangoproject.com/en/1.5/intro/tutorial01/#activating-models
>>> from django.utils import timezone
>>> p = Poll(question="What's new?", pub_date=timezone.now())
# Save the object into the database. You have to call save() explicitly.
>>> p.save()
# Now it has an ID. Note that this might say "1L" instead of "1", depending
# on which database you're using. That's no biggie; it just means your
# database backend prefers to return integers as Python long integer
# objects.
>>> p.id
1
quadright
Singularity
https://docs.djangoproject.com/en/1.5/intro/tutorial01/#activating-models

Просто и красиво, благодарю! Буду внимательнее мануал читать
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB