Hello

I have a form for model test (code below) that saves correctly. I wish
to add records to the modificationlog model every time an instance of
test is saved. What should be saved is the logged in user and the time
of the modification. The below is what I have tried to achieve this
goal, but it does not create new modification log records, in fact at
the moment it doesn't even modify an existing related modificationlog
record.

Can someone point out where I am going wrong please?

Thank you for your time





class Test(models.Model):
    first_name = models.CharField(max_length=255)
    modification_log = models.ManyToManyField(ModificationLog)

class ModificationLog(models.Model):
    modifier = models.ForeignKey(User)
    modified_on = models.DateTimeField(auto_now=True)

@login_required
@transaction.commit_on_success
def test(request, pk):
    a = get_object_or_404(Test.objects.select_related(), pk=pk)

    if request.method == 'POST':
        f = TestForm(request.POST, instance=a)
        if f.is_valid():
            modified =
ModificationLog.objects.create(modifier=request.user)
            a.modificationlog.add(modified)
            f.save()
        else:
            variables = RequestContext(request, {
                'appointment': a,
                'form': f,
            })
            return render_to_response('test/view_test.html',
variables)
    else:
        f = TestForm(instance=a)

    variables = RequestContext(request, {
        'test': a,
        'form': f,
    })

    return render_to_response('test/view_test.html', variables)

-- 
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