I have this code:
try:
principal = cls.objects.create(
user_id=user.id,
email=user.email,
path=\'something\'
)
except Integri
It could be better to use:
try:
obj, created = cls.objects.get_or_create(user_id=user.id, email=user.email)
except IntegrityError:
....
as in https://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create
The IntegrityError
should be raised only in the case there's a NOT NULL
constraint violation.
Furthermore you can use created
flag to know if the object already existed.