from django.db import models class City(models.Model): name = models.CharField(max_length=150, unique=True, verbose_name="City") class Meta: verbose_name_plural = "Cities" def __str__(self): return '{}'.format(self.name) class Location(models.Model): place = models.CharField(max_length=250, blank=True, null=False, verbose_name="Place") city = models.ForeignKey(City, on_delete=models.CASCADE, related_name='places', verbose_name="City") class Meta: verbose_name_plural = "Locations" unique_together = ('place', "city") ordering = ['city'] def __str__(self): if self.place: return '{0}, {1}'.format(self.city, self.place) else: return '{}'.format(self.city)