django objects.all() method issue
- by xlione
after I saved one item using MyModelClass.save() method of django in one view/page , at another view I use MyModelClass.objects.all() to list all items in MyModelClass but the newly added one always is missing at the new page. i am using django 1.1
i am using mysql
middleware setting
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
)
my model:
class Company(models.Model):
name = models.CharField(max_length=500)
description = models.CharField(max_length=500,null=True)
addcompany view
def addcompany(request):
if request.POST:
form = AddCompanyForm(request.POST)
if form.is_valid():
companyname = form.cleaned_data['companyname']
c = Company(name=companyname,description='description')
c.save()
return HttpResponseRedirect('/admins/')
else:
form = AddCompanyForm()
return render_to_response('user/addcompany.html',{'form':form},context_instance=RequestContext(request))
after this page
in another view
i called this form in another view
class CompanyForm(forms.Form):
companies=((0,' '),)
for o in CcicCompany.objects.all():
x=o.id,o.name
companies+=(x,)
company = forms.ChoiceField(choices=companies,label='Company Name')
to list all companies but the recently added one is missing.
The transaction should be successful, since after i do a apache server reboot , i can see the newly added company name
Thanks for any help...