eleom,

Thanks for the catch with country county in my model.

On Feb 20, 2:22 pm, eleom <[email protected]> wrote:
> Well, as the error message says, you must pass a County instance in
> the argument 'county'. Now you are passing the name of the county, not
> the county itself. So, your last line should be
>
> l = Company(name='xyz corp', address='56 b. street', client='G corp',
> city = 'Walla Walla', county=c, dollar_amount =54000)
>
> instead of
>
> l = Company(name='xyz corp', address='56 b. street', client='G corp',
> city = 'Walla Walla', county='blah blah', dollar_amount =54000)
>
> where c is the County object defined before.
>
> P.S. By the way, you mix 'County' and 'Country' in your example.
>
> On Feb 20, 8:06 pm, nixon66 <[email protected]> wrote:
>
> > If this is the wrong list to post a newbie question please let me
> > know. I'm getting an error message while trying to populate the tables
> > created by the models and not sure why. Here are the models
>
> > from django.db import models
>
> > class County(models.Model):
> >     name = models.CharField(max_length=80)
> >     slug = models.CharField(max_length=80)
>
> >     def __unicode__(self):
> >         return self.name
>
> >     def get_absolute_url(self):
> >         return "/countries/%s/" % self.slug
>
> > class Company(models.Model):
> >     name = models.CharField(max_length=50)
> >     address = models.CharField(max_length=80)
> >     client = models.CharField(max_length=50)
> >     city = models.CharField(max_length=50)
> >     county = models.ForeignKey(Country)
> >     dollar_amount = models.DecimalField('Cost (in dollars)',
> > max_digits=10, decimal_places=2)
>
> >     def __unicode__(self):
> >         return self.name
>
> > So I go into the shell and type this:
>
> > >>c=County(name='blah blah, slug="blah-blah")
>
> > then
>
> > >> l = Company(name='xyz corp', address='56 b. street', client='G corp', 
> > >> city = 'Walla Walla', county='blah blah', dollar_amount =54000)
>
> > The error message I get is Valueerror: Cannot assign "blah blah" :
> > "Company.county" must be a "County" instance.
>
> > doesn't this create the instance?
> >  >> c=County('blah blah', slug='blah-blah')
>
> > Any suggestion or point out my error would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to