django - Foriegnkey issue while submitting the form -


this post extends error while submitting data in form django

model.py  django.db import models  # create models here.  class profile(models.model):      name = models.charfield(max_length=50, primary_key=true)      assign = models.charfield(max_length=50)      doj = models.datefield()       class meta:         db_table= 'profile'        def __unicode__(self):         return  u'%s' % (self.name)    class working(models.model):    w_name =models.foreignkey(profile, db_column='w_name')    monday =  models.integerfield(null=true, db_column='monday', blank=true)    tuesday =  models.integerfield(null=true, db_column='tuesday', blank=true)    wednesday =  models.integerfield(null=true, db_column='wednesday', blank=true)     class meta:         db_table = 'working'       def __unicode__(self):       return  u'%s ' % ( self.w_name)   view.py  # create views here. forms import * django import http django.shortcuts import render_to_response, get_object_or_404   def index(request):    obj=working()    obj.w_name='x'    obj.monday=1    obj.tuesday=2    obj.wednesday =3    obj.save()    return http.httpresponse('added') 

here want insert data directly table ,if person click on http://127.0.0.1:8000/

but throws below error thoughts ??

exception type: valueerror @ / exception value: cannot assign "u'x'": "working.w_name" must "profile" instance.

i thought saying wanted inject values form?

in case, it's clear (see it's better comments), need pass in profile instance working object did in form clean method in other post.

def index(request):    try:         profile = profile.objects.get(pk='x')    except profile.doesnotexist:        assert false # or whatever wish    obj=working()    obj.w_name= profile    obj.monday=1    obj.tuesday=2    obj.wednesday =3    obj.save()    return http.httpresponse('added') 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -