On Fri, Feb 20, 2009 at 2:06 PM, nixon66 <nixon....@gmail.com> 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. > > > > > > > Yes, you create a County instance with County() however you aren't assigning that to county on the Company, you are assigning some string, you need to do Company(county=c). 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 -~----------~----~----~----~------~----~------~--~---