Ok, a project that a small team I am working on is new to django and developing a webapp, when all of a sudden we lost all ability to add a model object into the database. We are all at a complete loss. Below is where we are in debugging currently.
views.py
def postOp(request):
if request.method == 'POST':
operation = request.POST.get("operation","noop")
#Registered user operations
if request.user.is_authenticated():
username = request.session.get("member","Guest")
user = ToolUser.objects.get(name=username)
zipcode = user.location
.
.
#AddTool
if operation == "addTool":
toolName = request.POST.get("toolName","N/A")
toolDesc = request.POST.get("toolDesc","N/A")
print("In addtools")
user.submitTool(toolName, toolDesc)
print("SUBITTED")
return HttpResponseRedirect("tools")
model
def submitTool(self, Nname, Ndescription):
print("IN SUBMIT ")
t = Tool(name=Nname, owner=self.id, shed=self.id, description=Ndescription, currOwner=0, location=self.location)
print("tool made :", t.name, ", ", t.owner, ", ", t.shed, ", ", t.description, \
", ",t.currOwner ,", ", t.location)
t.save()
print("saving tool")
It appears that it gets all the way to the t.save(), then breaks. using a seperate tool to view the database, it is clearly not getting saved to the table. BUT with the following output to the terminal, it does appear to be creating this instance.
terminal output:
In addtools
IN SUBMIT
tool made : tooltest , 2 , 2 , description , 0 , 12345
EDIT: forgot to update this, found the problem, turns out one field was empty, and django refuses to save something that has empty fields.