Geeting filed name from one app models.py to another app models.py

We have defined two apps: Manin_matrix and SW_matrix. We want the field name (project_name) present in class GENERAL_t of modle.py file inside Main_matrix app to be inside the models.py file of SW_matrix app. Basically project_name_work field in class EDVT of SW_matrix models.py should be same as project_name of Main_matrix app. How to do this?
We want this so that in database for EDVT table we will get the same project id along with project name.

Main_matrix/models.py
class GENERAL_t(models.Model):
project_name = models.CharField(blank=True, null=True, max_length=40, verbose_name = ‘Project_Name’)
platform = models.CharField(blank=True, null=True, max_length=40, verbose_name = ‘Platform SW’)

SW_matrix/models.py
class EDVT(models.Model):
project_rel=models.ForeignKey(GENERAL_t,null=True,on_delete=models.SET_NULL,verbose_name=“Choose Project”)
project_name_work = models.ForeignKey(GENERAL_t.project_name, null=True, verbose_name = ‘Project_Name’)

That’s not how you use foreign key relationships. The idea of using a foreign key is to allow you to reference the data in the related model without actually copying it over. (See ForeignKey, and Related objects reference.)

For example (working somewhat from the code you provided):

class General_t(models.Model):
    project_name = models.CharField(blank=True, null=True, max_length=40, verbose_name = ‘Project_Name’)
    platform = models.CharField(blank=True, null=True, max_length=40, verbose_name = ‘Platform SW’)

class Edvt(models.Model):
    project_rel=models.ForeignKey(General_t, null=True, on_delete=models.SET_NULL, verbose_name=“Choose Project”)

So if you have a reference to an instance of Edvt, you can access the project_name of the related General_t model by following the foreign key field.
example:

edvt = Edvt.objects.get(id=<some id>)
project_name_work = edvt.project_rel.project_name

Ken

Hello Ken,
We tried this method earlier and it is not the solution of my question. Also, we cannot give the default value of id under edvt. We want field name from another models.py file of one app to another app models.py file. That filed name value is string and want to match the string and store in database as compared to related id number.

I’m sorry, it’s not clear what you’re asking for then.

To be clear from my side, that snippet I posted doesn’t go in the model. It (or something like it) would be in your view when you’re preparing data to be rendered. It’s got nothing to do with any defaults.

So the root question is whether or not you really need to copy that value as opposed to just using that value from the original table on an as-needed basis. If you could be more explicit as to why you think you want to do this, we might be able to supply a better answer.