[Fixed]-Django model for city and places

1👍

You can simply remove city field from your Property class because location contains city in it.

To retrieve property city you can do something like this:

models.py

class Property(models.Model):
    # *Your codes here*

    # *define new method*
    def get_city(self):
        return self.location.city()

And then you can use this method every where you need:

admin.py

class PropertyAdmin(admin.ModelAdmin):
    list_display = ['title', 'slug', 'address', get_city, 'status']

or:

>>> A = Property.objects.get(id = 1)
>>> A.get_city()

Leave a comment