tags:

views:

75

answers:

1

I have a model using the GeoIP library to render the country of the IP address for that record:

class PageIP(models.Model):
"""
Detail of page
"""
ip_address = models.IPAddressField(blank=True,verbose_name="IP Address")


def _client_country(self):
    g = GeoIP()
    return g.country(self.ip_address)

client_country = property(_client_country)

Is there any way to show this property (client_country) in the Django 1.1 admin? As currently written, this doesn't appear in the admin.

Cheers.

A: 

you should put it into the admin.py file:

from django.contrib import admin 
admin.site.register(PageIP)

and it will appear there shortly. also, make sure your app is in settings.py under INSTALLED_APPS

ifesdjeen
The model is there, as is the field ip_address.I need client_country in the admin though.
Adam Nelson
why not try __str__(self)? for writing into you should add a setter as well, not only getter.
ifesdjeen
great idea - that's so obvious I didn't think about it. I'll use __unicode__(self) though.
Adam Nelson