Re: Contact Enquiry model expecting identity value

2009-03-22 Thread grimmus

Sorry, i am a bit of a beginner at Django and Python.

I am following the contact form tutorial from chapter 7 of the new
book and instead of emailing the form contents i want to save it to a
database.

I referenced the model part from the main Django tutorial on the
website.

Ill have a look into ModelForm, i havent heard of it before

Thanks

On Mar 22, 8:59 pm, Alex Gaynor  wrote:
> On Sun, Mar 22, 2009 at 3:57 PM, grimmus  wrote:
>
> > I am creating an instance of the model in a view like so:
>
> > form = ContactForm(request.POST)
> >        if form.is_valid():
> >            cd = form.cleaned_data
>
> >            c = ContactEnquiry(cd['name'],cd['subject'],cd['email'],cd
> > ['message'],datetime.datetime.now())
> >            c.save()
>
> >            return HttpResponseRedirect('/contact/thanks/')
>
> > if i enter an integer before cd['name'] the instance gets saved in the
> > database but this integer should be an identity/autonumber value.
>
> > On Mar 22, 8:06 pm, Alex Gaynor  wrote:
> > > On Sun, Mar 22, 2009 at 3:00 PM, grimmus 
> > wrote:
>
> > > > Hi,
>
> > > > I have a class like so
>
> > > > class ContactEnquiry(models.Model):
> > > >    name = models.CharField(max_length=100)
> > > >    subject = models.CharField(max_length=100)
> > > >    email = models.EmailField()
> > > >    message = models.CharField(max_length=100)
> > > >    enquiry_date = models.DateTimeField('enquiry date')
> > > >    def __unicode__(self):
> > > >        return self.name
>
> > > > when i make an instance of this class it throws the error :
>
> > > > invalid literal for int() with base 10: 'name value'
>
> > > > when i pass an int as the first parameter it works fine but i thought
> > > > an autonumber would be passed as the id value ?
>
> > > > Thanks for any help
>
> > > How are you creating an instance of the model, can you paste the code you
> > > are running and the full traceback.
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> You're passing the name as the first param, which is by default the primary
> key.  You can avoid that by passing everything as kwargs.
>
> Is there any reason you aren't using a ModelForm though?
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Contact Enquiry model expecting identity value

2009-03-22 Thread Alex Gaynor
On Sun, Mar 22, 2009 at 3:57 PM, grimmus  wrote:

>
> I am creating an instance of the model in a view like so:
>
> form = ContactForm(request.POST)
>if form.is_valid():
>cd = form.cleaned_data
>
>c = ContactEnquiry(cd['name'],cd['subject'],cd['email'],cd
> ['message'],datetime.datetime.now())
>c.save()
>
>return HttpResponseRedirect('/contact/thanks/')
>
> if i enter an integer before cd['name'] the instance gets saved in the
> database but this integer should be an identity/autonumber value.
>
> On Mar 22, 8:06 pm, Alex Gaynor  wrote:
> > On Sun, Mar 22, 2009 at 3:00 PM, grimmus 
> wrote:
> >
> > > Hi,
> >
> > > I have a class like so
> >
> > > class ContactEnquiry(models.Model):
> > >name = models.CharField(max_length=100)
> > >subject = models.CharField(max_length=100)
> > >email = models.EmailField()
> > >message = models.CharField(max_length=100)
> > >enquiry_date = models.DateTimeField('enquiry date')
> > >def __unicode__(self):
> > >return self.name
> >
> > > when i make an instance of this class it throws the error :
> >
> > > invalid literal for int() with base 10: 'name value'
> >
> > > when i pass an int as the first parameter it works fine but i thought
> > > an autonumber would be passed as the id value ?
> >
> > > Thanks for any help
> >
> > How are you creating an instance of the model, can you paste the code you
> > are running and the full traceback.
> >
> > Alex
> >
> > --
> > "I disapprove of what you say, but I will defend to the death your right
> to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
> >
>
You're passing the name as the first param, which is by default the primary
key.  You can avoid that by passing everything as kwargs.

Is there any reason you aren't using a ModelForm though?

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: Contact Enquiry model expecting identity value

2009-03-22 Thread grimmus

I am creating an instance of the model in a view like so:

form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data

c = ContactEnquiry(cd['name'],cd['subject'],cd['email'],cd
['message'],datetime.datetime.now())
c.save()

return HttpResponseRedirect('/contact/thanks/')

if i enter an integer before cd['name'] the instance gets saved in the
database but this integer should be an identity/autonumber value.

On Mar 22, 8:06 pm, Alex Gaynor  wrote:
> On Sun, Mar 22, 2009 at 3:00 PM, grimmus  wrote:
>
> > Hi,
>
> > I have a class like so
>
> > class ContactEnquiry(models.Model):
> >    name = models.CharField(max_length=100)
> >    subject = models.CharField(max_length=100)
> >    email = models.EmailField()
> >    message = models.CharField(max_length=100)
> >    enquiry_date = models.DateTimeField('enquiry date')
> >    def __unicode__(self):
> >        return self.name
>
> > when i make an instance of this class it throws the error :
>
> > invalid literal for int() with base 10: 'name value'
>
> > when i pass an int as the first parameter it works fine but i thought
> > an autonumber would be passed as the id value ?
>
> > Thanks for any help
>
> How are you creating an instance of the model, can you paste the code you
> are running and the full traceback.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Contact Enquiry model expecting identity value

2009-03-22 Thread Alex Gaynor
On Sun, Mar 22, 2009 at 3:00 PM, grimmus  wrote:

>
> Hi,
>
> I have a class like so
>
> class ContactEnquiry(models.Model):
>name = models.CharField(max_length=100)
>subject = models.CharField(max_length=100)
>email = models.EmailField()
>message = models.CharField(max_length=100)
>enquiry_date = models.DateTimeField('enquiry date')
>def __unicode__(self):
>return self.name
>
> when i make an instance of this class it throws the error :
>
> invalid literal for int() with base 10: 'name value'
>
> when i pass an int as the first parameter it works fine but i thought
> an autonumber would be passed as the id value ?
>
> Thanks for any help
>
> >
>
How are you creating an instance of the model, can you paste the code you
are running and the full traceback.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Contact Enquiry model expecting identity value

2009-03-22 Thread grimmus

Hi,

I have a class like so

class ContactEnquiry(models.Model):
name = models.CharField(max_length=100)
subject = models.CharField(max_length=100)
email = models.EmailField()
message = models.CharField(max_length=100)
enquiry_date = models.DateTimeField('enquiry date')
def __unicode__(self):
return self.name

when i make an instance of this class it throws the error :

invalid literal for int() with base 10: 'name value'

when i pass an int as the first parameter it works fine but i thought
an autonumber would be passed as the id value ?

Thanks for any help

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