modeladmin

Can "list_display" in a Django ModelAdmin display attributes of ForeignKey fields?

I have a Person model that has a foreign key relationship to Book. Book has a number of fields, but I'm most concerned about "author" (a standard CharField). With that being said, in my PersonAdmin model, I'd like to display "book.author" using "list_display". I've tried all of the obvious methods for doing so (see below), but nothing...

Django: accessing the model instance from within ModelAdmin?

I've got a model for Orders in a webshop application, with an auto-incrementing primary key and a foreign key to itself, since orders can be split into multiple orders, but the relationship to the original order must be maintained. class Order(models.Model): ordernumber = models.AutoField(primary_key=True) parent_order = models....

Override of ModelAdmin.save_model not being called

Hi All I'm using the GenerickStackedInline which is a subclass of InlineModelAdmin which goes to ModelAdmin. When I override save_model method... it's not being called. class LocatedItemStackedInline(generic.GenericStackedInline): template = "admin/location_app/located_items/stacked.html" model = LocatedItem extra = 1 f...

Disable link to edit object in django's admin (display list only)?

In Django's admin, I want disable the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields). I see that Django has the ability to choose which fields display the link, ho...

Django: Overriding ModelAdmin save_model not working

Even after obj.save(), the obj still does not have an id, so I cannot access or manipulate the m2m records. Just keep getting a "instance needs to have a primary key value before a many-to-many relationship can be used" error. def save_model(self, request, obj, form, change): obj.save() # this doesn't work super(Table2Admin, sel...

Django admin: how do I add an unrelated model field to a model change/add page?

I have the following models: class Foo(models.Model): field1 = models.IntegerField() ... class Bar(models.Model): field1 = models.IntegerField() ... class Foo_bar(models.Model): foo = models.ForeignKey(Foo) bar = models.ForeignKey(Bar) ... In the admin, I want it so that in the Foo change/add page, you ca...

Django - Access parent window in ModelAdmin

Hello, I have a class called News which have a choices field called category. Each category is also representing by classes with the News class as foreignKey field. So in admin, when I create a new category instance, I have to create a News, which is represented with a popup. The main page which represents the category class is the p...

change list display link in django admin

I am trying to change the link for an object in the django admin list display. Here is what I have so far: class FooModelAdmin(admin.ModelAdmin): fields = ('foo','bar') list_display = ('foo_link','bar') def foo_link(self,obj): return u'<a href="/foos/%s/">%s</a>' % (obj.foo,obj) domain_link.allow_tags = True ...