Hi Guys,

I was trying to use the newly introduced ModelAdmin.get_readonly_fields
method to mark a OneToOne relation as read only - something along the lines
of:

models.py:
class Book(models.Model):
    title = models.CharField(max_length = 50)
    ...

    def __unicode__(self):
        return '%s' % self.title

class BookInventory(models.Model):
    ...
    book = models.OneToOneField(Book)

    def __unicode__(self):
        return '%s' % self.book

admin.py:
class BookInventoryAdmin(admin.ModelAdmin):
    def get_readonly_fields(self, request, obj = None):
        if obj is not None:
            return ['book']
        else:
            return []

While this works just fine, the one problem I'm having is that instead of
showing the title of the book (i.e. - calling Book.__unicode__), the admin
simply shows the primary key value of the Book.

This issue was bug #342 in Django Trac - [1] - and was fixed in
changeset 11965 - [2].

Does anyone have any ideas about how to get the title of the book to show up
in the admin page for BookInventory, instead of it's primary key value?

Thanks in advance,

Rishabh

[1] - http://code.djangoproject.com/ticket/342
[2] - http://code.djangoproject.com/changeset/11965

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to