how to get only one column from a entire table using foreign key in Django

Viewed 221

I'm working on a Django project. where I need to map the fields using foreign key.

how to add only one field instead of whole table using foreign key ?

1 Answers

You can implement the __str__ method to specify how it should show the Developer object:

class Developers(models.Model):
    # …
    
    def __str__(self):
        return self.Developer_Name

Note: normally a Django model is given a singular name, so Developer instead of Developers.


Note: normally the name of the fields in a Django model are written in snake_case, not PascalCase, so it should be: developer_name instead of Developer_Name.

Related