I have this very simple view:
from models import Item, Tag, Category, User
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
def save_item(request):
try:
print request.GET
i = Item()
i.user = User.objects.get_or_create(email=request.GET['user_email'][0])
i.save()
print i
except Exception as e:
print e.message()
return HttpResponse()
with these very simple models:
class User(models.Model):
email = models.EmailField()
class Item(models.Model):
category = models.ForeignKey(Category, null=True, blank=True)
tags = models.ManyToManyField(Tag, null=True, blank=True)
address = models.CharField(max_length = 512, null=True, blank=True)
user = models.ForeignKey(User)
data = models.CharField(max_length = 1024, null=True, blank=True)
the print is the only thing that shows in my error.log:
[Wed May 16 01:23:40 2012] [error] <QueryDict: {u'website': [u''], u'comment': [u''], u'rating': [u''], u'phone number': [u''], u'address': [u''], u'user_email': [u'cc.emeraldeyes@gmail.com']}>
but the Item model instance is not created!
I can manually create one in the admin or in the shell:
ubuntu@ip-10-196-47-228:~/WeShouldServer$ ./manage.py shell
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from RemoteStorage.models import Item
>>> i = Item()
>>> from RemoteStorage.models import User
>>> i.user = User.objects.get(pk=1)
>>> i.save()
# THIS WORKS
but trying to save one in the view just... fails. Silently. WHYYYY??!!!