Created
October 15, 2010 21:44
-
-
Save lamikae/629007 to your computer and use it in GitHub Desktop.
get or create user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import time | |
from django.db import models, connection | |
from myapp.models import OraAbbOy1001 | |
id = # comes somewhere | |
try: | |
user = OraAbbOy1001.objects.get(id=id) | |
except OraAbbOy1001.DoesNotExist: | |
# select nextval from ID sequence | |
seq_name = 'q1001user' | |
cursor = connection.cursor() | |
cursor.execute("SELECT %s.NEXTVAL FROM DUAL" % seq_name) | |
userid = cursor.fetchone()[0] | |
# create new user | |
user = OraAbbOy1001.objects.create( | |
id=userid, | |
name='Vic Video', | |
create_date=time.strftime('%Y-%m-%d',time.localtime()), | |
) | |
log.info("OraAbbOy1001 user id %i (%s) created" % ( | |
user.id, | |
user.name | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment