Re: Forienkey to same table

2020-03-30 Thread Motaz Hejaze
What are the usages lf such a technique ??

On Mon, 30 Mar 2020, 11:16 am Metehan Gülaç,  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+unsubscr...@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+unsubscr...@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.


Re: Forienkey to same table

2020-03-30 Thread Metehan Gülaç
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+unsubscr...@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.


Re: Forienkey to same table

2020-03-29 Thread Stephen J. Butler
Instead of using the model class, or string name of the model class, use
the string value 'self'.

https://docs.djangoproject.com/en/3.0/ref/models/fields/#foreignkey

On Sun, Mar 29, 2020 at 9:44 PM Mohsen Pahlevanzadeh <
m.pahlevanza...@gmail.com> wrote:

> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJFFGZKZLQDNMA%2BzSUFKvUX8c0eMe%2B7do73cV1RyZTO1q-A3gg%40mail.gmail.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxVFOKpakv8OBP6FQXnCyfnskhsxgkXfbf22DL%3DB8E-c%3Dg%40mail.gmail.com.


Forienkey to same table

2020-03-29 Thread Mohsen Pahlevanzadeh
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJFFGZKZLQDNMA%2BzSUFKvUX8c0eMe%2B7do73cV1RyZTO1q-A3gg%40mail.gmail.com.