Hi everyone,  this issue is related simply to using jquery's $.post to
send some data to my view. I want to edit an item via Ajax (i..e the
way de.li.cious lets you edt an item without refreshing page) :

JAVASCRIPT
-------------
<pre>
data =  { "name":"apple",
                  "id":ingred_id,
                  "category":"",
                  "stock_status":0,
                  "storename":"albertsons",
                  "user":0
                  };

$.post(url,data,processSuccessfulEdit, "json");
</pre>

VIEWS.PY
-----------
 #  first get the item to edit-----------
 id = request.POST['id']
 Item  = Ingredient.objects.get(pk=int(id))

 # then save it
 Ingr = IngredientEditForm(request.POST, instance=I)
 Ingr.save()

 The problem is that the form validation fails. And it's because I'm
sending a blank string in the category field. This field, in the
Ingredient table, is null=TRUE, so I was expecting it to work.

If I launch a python shell manually and run this:
----------------------------------
p =  Ingredient
(name="testingr",category_id="",stock_status=1,user_id=0,storename="vons")
p.save()

It works, it gets inserted succesfully. Django accepts the blank
string and creates a record with this foreign integer field as null.

I'm thinking I should put aside the usage of ModelForm for now and
manually do the updating of the record in the view function,  unless
there's something I'm not doing right.

Wondering if anyone had run into this
thanks,
Steve
=====================================================

in case needed, here is the modelform class as well
--------------------------------------------------------------
class IngredientEditForm(ModelForm):
    class Meta:
        model = Ingredient

class Ingredient(models.Model):
    name = models.CharField(max_length=250)
    stock_status = models.PositiveSmallIntegerField()
    category = models.ForeignKey(Ingredcategory, null=True)
    user = models.ForeignKey(FhyUser)
    storename = models.CharField(max_length=50)

    def __unicode__(self):
        return self.name
    class Meta:
        db_table = u'ingredient'


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to