Q:

Django: Can i link 2 model fields instead of the model class?

Here is my code below,
models.py
class Random(models.Model):
    Random_name = models.CharField(max_length=250)
    Rand_ID = models.CharField(max_length=100)

class Input(models.Model):
    Input_name = models.CharField(max_length=250)
    iref_id = ?? (To be linked with Rand_ID)
    is_req=models.CharField(max_length=100)

Im trying to link Rand_ID to iref_id so that for a particular Rand_ID, i can have Many inputs.
I know that i can link Random class using ForiegnKey however can i link Rand_ID in any way?
PS- Rand_ID is not the Primary Key of Random.
All answers are welcome.
EDIT:
Rand_ID has unique Values.

A:

You can use ForeignKey with to_field argument:
iref_id = ForeignKey(Random, on_delete=models.CASCADE, to_field='Rand_ID')

Note you can use as to_field only with fields marked as unique=True:
Rand_ID = models.CharField(max_length=100, unique=True)

