Hello Ben,

I'm not really sure what you mean by leave the _id out.
What i did with the sponsor_id and method_id was getting the correct
objects from the Method and Sponsor class

The Client class i believe is a attribute of both ( Sponsor and
Method )
If you use only one ForeignKey the normal code to add some values
would be

sponsor = Sponsor.objects.get(sponsor_id=1)

sponsor contains the Sponsor object for sponsor_id 1
next you could add data in clients by

sponsor.clients_set.create(labcode=101,invoiceNr='None')

The problem is that clients is not only a attribute from sponsor but
also from method
so this way of getting values in the clients table won't work. because
you have to reference both sponsor as method and that gives the
attributeError

if i would use sql queries i could just add the sponsor and method
values in the table that are related to the same values in the sponsor
and method class
but i'm interested in seeing how Django would deal with this.

if anyone knows how to deal with this, i would really appreciate the
help.

Regards,

Richard



On Dec 19, 6:19 pm, "Ben Ford" <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to