0

I'm currently trying to code a a simple website where what you submit to the website is is validated and then saved into a database using this bit of code.

def referral_create(request):
    if request.method == 'POST':
        form = CashtextsForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('Submitted_page.html')
    else:
        form = CashtextsForm()
        return render_to_response('CashTextsubmit.html')

It works fine (I think) but when i run a Cashtexts.objects.all() on it. The database only returns 2 items from the database even tho I have "submitted" tens of things through the actual web interface.

I really have zero knowledge of Databases so I'm not sure if this is normal or if I'm looking in the wrong place or what is really going on here. any help is appreciated.

Edit: here is the file of Models.py

from django.db import models
from django.forms import ModelForm

class Cashtexts(models.Model):
    cashcode = models.CharField(max_length=100)

    def __unicode__(self):
        return self.cashcode

class CashtextsForm(ModelForm):
    class Meta:
        model = Cashtexts
6
  • Please post the definition of CashtextsForm Commented Feb 16, 2012 at 6:48
  • alight I posted it hopefully that helps some. Commented Feb 16, 2012 at 15:55
  • First thing I'd check is whether the database has been set up correctly: What's in your DATABASES in settings.py? Commented Feb 16, 2012 at 16:26
  • When you say "web interface", are you talking about the admin or this form that you have created? Commented Feb 16, 2012 at 16:54
  • the form. I go to the page (127.0.0.1:8000/CashTextsubmit) in chrome that shows the form and I submit something and it brings me to the "yay you thing has been submitted" page. then I wrote this Cashtexts.objects.all() into a function and template told it to display that onto the webpage. <br /> and I went through the database set up that was in the book and it set up with zero errors. I'll browse it over again. also everytime I want to use the web app from my computer do I have to somehow "activate" the database? or is that what is being accomplished through the seetings.py file? Commented Feb 16, 2012 at 21:46

1 Answer 1

1

you can try debugging like

  • Try Django Shell option ,so that you can check what's going wrong while saving the object
  • Another check is that if you are aware of SQL query you can check directly into database exact how many values getting store

Hope it will help you.

Sign up to request clarification or add additional context in comments.

1 Comment

hmmph. thanks for the help. What more would you need to know in order to better help me? or were you saying something different in your header?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.