On Mon, Nov 27, 2017 at 5:30 PM, Matemática A3K <matematica....@gmail.com>
wrote:

>
>
> On Mon, Nov 27, 2017 at 10:50 AM, Kubilay Yazoğlu <kyazog...@gmail.com>
> wrote:
>
>> Thanks for your answer. I have one more question. What if there are more
>> than one primary keys in that table?
>>
>
> By definition, that won't happen, a primary key is unique. If you add a
> record with the same key Django will raise an IntegrityError.
>
>
>> I'm talking about the unique_together case.
>>
>
> I don't understand you
>

The ForeignKey uses the model's auto primary key to "link", if you define
other keys, np. You should read
https://docs.djangoproject.com/en/1.11/ref/models/fields/#foreignkey

The __str__() representation of the object is independent of the keys you
define on it. If you want to tweak what is displayed in the drop-down, use
this method to show whatever you need :)


>
>
>>
>> 27 Kasım 2017 Pazartesi 08:55:45 UTC+3 tarihinde Matemática A3K yazdı:
>>>
>>> What Django shows in that dropdown is the __str__() method of the
>>> object, define it to your needs in A :)
>>>
>>> On Sun, Nov 26, 2017 at 7:49 PM, Kubilay Yazoğlu <kyaz...@gmail.com>
>>> wrote:
>>>
>>>> Hello. I have two models. In one of them, I declared a foreign key to
>>>> the other one. Since this is done in Django by only specifying the Class
>>>> name, without specifying the field name(column name), when I try to create
>>>> an object in admin panel, it pulls the wrong column information.
>>>>
>>>> Two models A and B.
>>>> B has a Foreignkey for accessing A.
>>>> A has two fields Field1 and Field2.
>>>> When I try to create an instance of B, in the field of Foreignkey,
>>>> there is a drop down menu but the content is not from the right field of A.
>>>>
>>>> How to specify it?
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/django-users/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%40goog
>>>> legroups.com
>>>> <https://groups.google.com/d/msgid/django-users/ad0d40a3-cd7f-4f2f-821d-31cc007657b1%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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/60af36a5-7fec-46f7-a348-ae4a8784f01b%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/60af36a5-7fec-46f7-a348-ae4a8784f01b%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BFDnhJ4ZxTmTwP1DKc30ACBpOcS6npTJLDSfEKpZ8xRUKGrxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to