I'm trying to display more information in a admin panel and can't I have two models with foreign Key I trying show streets list and add to street name City name
class Street(models.Model):
name = models.CharField(max_length=50, verbose_name='Street')
code = models.IntegerField()
city = models.ForeignKey('City', on_delete=models.PROTECT, null=True)
class Meta:
managed = True
db_table = 'street'
def __str__(self):
return self.name + f'({self.city.name})'
class City(models.Model):
name = models.CharField(max_length=50, verbose_name='City')
code = models.IntegerField()
class Meta:
managed = True
db_table = 'city'
def __str__(self):
return self.name+ f' ({self.code})'
source https://stackoverflow.com/questions/73071617/django-admin-panel-show-foreignkey-data
Comments
Post a Comment