Luke Seelenbinder wrote:
> I'm am trying to make a ForeignKey with a default value.
> But when I save i get a "invalid literal for int() with base 10: 'Stat
> object'" error
> Here is my code:
>
> from django.db import models
>
> class Stat(models.Model):
>     total               =   models.IntegerField(default=0)
>     right               =   models.IntegerField(default=0)
>     wrong               =   models.IntegerField(default=0)
>
>     def percent_right(self):
>         return (float(right) / total) * 100
>
> class Noun(models.Model):
>
>     word                =   models.CharField(max_length='50',
> unique=True)
>
>     definition          =   models.CharField(max_length='100',
> default=Stat())
>
>     definition_stats    =   models.ForeignKey(Stat, default=Stat(),)
>
>     GENDER_CHOICES      =   (
>         (True, 'Masculine'),
>         (False,'Feminine'),
>         (None, 'Neuter'),
>     )
>     gender              =   models.BooleanField(blank=True, null=True,
> choices=GENDER_CHOICES)
>     gender_stats        =   models.ForeignKey(
>                                 Stat,
>                                 default=Stat(),
>                                 related_name='gender_stats',
>                             )
>
>     plurality           =   models.CharField(max_length='50',)
>
> class Verb(models.Model):
>     word                =   models.CharField(max_length='50',
> unique=True)
>
>     definition          =   models.CharField(max_length='100',)
>     definition_stats    =   models.ForeignKey(Stat, default=Stat(),)
>
>     irregular           =   models.BooleanField()
>
>   
Have you tried reading a Stat instance in from the database and using
that as the default value? The one you currently use hasn't been saved
anywhere, and therefore has a None primary key (though it looks to me as
though the instance is being used where a primary key value is required,
so maybe the default value should be the primary key of an existing
instance?).

regards
 Steve


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to