Monday, March 30, 2020

Re: Forienkey to same table

What are the usages lf such a technique ??

On Mon, 30 Mar 2020, 11:16 am Metehan Gülaç, <metehanglc@gmail.com> wrote:
first of all, you can remove the 1. id (pK) line. django already create this field for you in background. I think you want to reference id field of A table to himself; it is known as recursive relationship. Speaking the which, you can use:

models.ForeignKey('self', on_delete=models.CASCADE)


30 Mart 2020 Pazartesi 05:45:11 UTC+3 tarihinde Mohsen Pahlevanzadeh yazdı:
I have table A with my following fields:
1. id (PK)
2. fname (text)
3. name (text)
4. A_id (integer)

I have problem with 4th field, Because it has to refrenced to id
field. I can't implement it into Django.

How can I write model class for above table in models.py ?

--mohsen

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ebd316df-e70f-4e7e-ba02-55fede43909e%40googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-d4fu8x7Qb8XsUimsZY_YS1BM6%3DbOP0ZyQNYwwB546LUQ%40mail.gmail.com.

No comments:

Post a Comment