You are probably looking for a many-to-many relationship using an
intermediary table:

https://docs.djangoproject.com/en/1.8/topics/db/models/#intermediary-manytomany

-James
On Aug 6, 2015 3:06 AM, "Holland_zwz" <holland...@gmail.com> wrote:

> Sometimes table have more than one foreign key reference to other tables.
> Then how to descript it in model?
>
> For eg:
>
> Table A:
> create table A (
>    oid                  varchar(10)          not null,
>    pid                  varchar(10)          not null,
>    color               varchar(20)          null
> )
> alter table A add constraint A_PK primary key (oid)
>
> Table B:
> create table B(
>    oid                  varchar(10)         not null,
>    pid                  varchar(10)         not null,
>    name              varchar(100)        null
> )
> alter table B add constraint B_PK primary key (oid)
>
> Table C:
> create table  C (
>    id                   varchar(10)          null,
>    cid                  varchar(10)          null,
>    oid                  varchar(10)          null
> )
>
> alter table  C add constraint C_FK1 foreign key (oid) references A(oid)
> alter table C add constraint C_FK2 foreign key (oid)  references B(oid)
>
>
> in this case, how to descript it in model?
>
> class ModelA(models.Model):
>       oid = models.CharField(max_length=10,primary_key=True)
>       ...
>
> class ModelB(models.Model):
>       oid = models.CharField(max_length=10,primary_key=True)
>       ...
>
> class ModelC(models.Model):
>       oid = models.ForeignKey(...) ?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9b1318e7-87b4-49b2-aad2-3a1dff41fa7f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9b1318e7-87b4-49b2-aad2-3a1dff41fa7f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXBqqsDvBM0fbGXrVteEJBefUj4YPxrDVgCLLjFOMgPDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to