views:

38

answers:

2

Hi guys, i want to save data in two table mysql, that was nice, but now i change a field form Interget to FK.. the problem is that now i cant send the data to the field FK....

im new with Django, but im working in this way:

@login_required
def agregar_diligencia(request):    
    if request.method =='POST':
        form = DiligenciaForm(request.POST)
        #trac = Tracking()
        tracknum = 'ABCD458LK'
        if form.is_valid():
            from django.contrib.auth.models import User            
            User = User.objects.get(pk=request.user.id)            
            obj = form.save(commit=False)                        
            obj.socio = User            
            obj.status = 0            
            obj.secuencia = 1
            obj.save()
            t = Tracking()            
            t.track = tracknum
            t.diligencia = obj.id
            t.save()

            return HttpResponseRedirect('/accounts/diligencias/activas')


    else:  
        form = DiligenciaForm()

    return render_to_response('account/agregar_diligencia_form.html', 
                 { 'formulario':form },context_instance = RequestContext(request))

Where t.diligencia = obj.id (t.diligencia) is my FK and obj.id is the data that i want to save in the FK

Sorry with my English and thanks.

A: 

You haven't at all stated what the problem is.

However one thing that I can see is that you're overwriting User in this line:

    User = User.objects.get(pk=request.user.id)

You should be assigning to user with a lower-case u - but I doubt that's the source of your problem, whatever it is.

Daniel Roseman
A: 

just do

obj.socio = request.user
Jason Christa