Try this:
class Clients(models.Model):
labcode = models.AutoField(primary_key = True)
invoiceNr = models.IntegerField()
sponsor = models.ForeignKey(Sponsor)
method = models.ForeignKey(SubmitMethod)
sponsor_id is the actual value stored in the db (i.e the pk value of the
instance that the ForeignKet points at). If you get rid of the _id from the
end of the field name it should work.
Ben
On 19/12/2007, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> Hello Django Users,
>
> I just started working with django again but i'm running into some
> troubles adding values into my database.
> just for an example i made the following three tables
>
>
> class Method(models.Model):
> method_id = models.AutoField(primary_key=True)
> methodName = models.CharField(max_length=20)
>
> class Sponsor(models.Model):
> sponsor_id = models.AutoField(primary_key=True)
> sponsorName = models.CharField(max_length=50)
>
> class Clients(models.Model):
> labcode = models.AutoField(primary_key = True)
> invoiceNr = models.IntegerField()
> sponsor_id = models.ForeignKey(Sponsor)
> method_id = models.ForeignKey(SubmitMethod)
>
>
> I added some values into the tables method and sponsor and now i want
> to add the values into the table clients. The problem is that it has
> multiple foreignkeys and the method from the tutorial doesn't work in
> this case
>
> sponsor = Sponsor.objects.get(sponsor_id=1)
> method = Method.objects.get(method_id=1)
>
>
> sponsor.method.clients_set.create(labcode=101,invoiceNr='None')
>
> the error it states is the following
> AttributeError: 'Sponsor' object has no attribute 'method'
>
> offcourse that is correct because only clients is a attribute from
> sponsor.
>
> Can someone help me out, how can i add values to this table using the
> django method ? ( offcourse i can fall back to sql querying but i like
> to know the django way )
>
> any help would be greatly appreciated,
>
> Regards,
>
> Richard M
>
>
>
>
> >
>
--
Regards,
Ben Ford
[EMAIL PROTECTED]
+6281317958862
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---