foregin key using name value fetch in django rest frame work
Question:
Answers:
Override the __str__()
function in model class to customize the dropdown correctly.
class Country(models.Model):
# your data variables
def __str__(self):
return self.name # or any thing you want to show in dropdown
same you can do with state too.
As Vinay has stated, add a return method to return some sort of detail to all your models. Also, make sure your model names start with a capital letter and there is no need to define the id as Django will always create that for you.
Override the __str__()
function in model class to customize the dropdown correctly.
class Country(models.Model):
# your data variables
def __str__(self):
return self.name # or any thing you want to show in dropdown
same you can do with state too.
As Vinay has stated, add a return method to return some sort of detail to all your models. Also, make sure your model names start with a capital letter and there is no need to define the id as Django will always create that for you.