Django model object initialization

If I do

obj = Object()
obj.att1 = 'test'
obj.att2 = 'test'
obj.save()

obj.id --> works fine

But if I do

obj=Object(att1='test',att2='test').save()

Doing obj.id --> obj seems to be Nonetype at this stage

Is this the case?

Answers


I don't know the exact framework you are using, but I am going to take a guess as to the problem:

Object(att1='test',att2='test').save()

The save() function doesn't appear to return the Object instance, it returns None. So you would normally:

obj=Object(att1='test',att2='test')
obj.save()

Then check obj.id.


Need Your Help

Migration From Datatable to Linq to Sql

asp.net linq-to-sql datatable

In past I use dynamic sql and datatable to get data from database.

Social logins and retaining access without having to authenticate every time…is it possible?

twitter facebook oauth

I am about to start a new project building a web UI with a lot of different functionality. Part of the functions however include the ability to update and access certain social media sites - Facebo...