You need to set few additional attributes in your foreign key.

First you have to use db_column='', and to_field=''

db_column value would be column name in your table that holds foreign key.
I guess this would be 'name2' in your model that reflects table2

to_field would be reference in field in a model that reflects table1 db
column name1

So as a simplified example:

class MyModel1(models.Model):
    name1 = model.CharField(max_length=123)

    class Meta:
        db_table = 'table1'

class MyModel2(models.Model):
    name2 = model.ForeignKey('myapp.MyModel1', db_column='name2',
to_field='name1')

    class Meta:
        db_table = 'table1'

Hope that helps.


On Thu, Nov 5, 2015 at 6:12 PM, frocco <faro...@gmail.com> wrote:

> Thank you
>
> On Wednesday, November 4, 2015 at 11:19:40 AM UTC-5, frocco wrote:
>>
>> Hello,
>>
>> I have two existing tables
>> table1 has name1
>>
>> table2 has name2
>>
>> when I edit table2 in admin, I want a dropdownbox that shows values from
>> table1 using name1
>> both fields are character
>>
>> I cannot change the design, porting from msaccess
>>
>> thanks
>>
>> --
> 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/f42b087f-dffe-42df-994b-22e9028dd4c7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f42b087f-dffe-42df-994b-22e9028dd4c7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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/CAHn91ofvaaSWR-VPd9%3Dppc%3DOuM4Huo38Hf4zfb%2B-LmDcX0biYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to