On Oct 16, 12:57 pm, lipt0n <michal.lipin...@gmail.com> wrote: > Hi, > I'm trying to make a list_display dynamically from other model. > > it looks like that: > models: > > class Headers(models.Model): > name = models.IntegerField() > active = models.BooleanField() > class Table(models.Model): > p1 = models.TextField(null=True, blank=True) > p2 = models.TextField(null=True, blank=True) > p3 = models.TextField(null=True, blank=True) > > admin: > class TableAdmin(admin.ModelAdmin): > list_display=[] > for x in list(Headers.objects.filter(active=True)): > list_display.insert(0, 'p%i' %x.name) > > and it's works great, but if I change something on Headers it doesn't > change anything in TableAdmin.list_display until I restart the > server. It is some kind of caching? > I already tried to override save method of "Headers" model where I > try to admin.site.unregister TableAdmin, build list_display and > register it again with no luck. > > Please help me, how I can make it work?
This isn't caching. What's happening is that the for loop is executed when the TableAdmin is *defined*. That happens the first time it is imported, which is when admin.autodiscover() is called from your urls.py - which in turn happens whenever Apache starts a new process. A process is long-lived and serves multiple requests, and the value will persist across all of them. If you're using the development server, it will persist until you reset the server (or it resets itself in response to a code change). There isn't really a good way of making this dynamic - it's not one of the areas of the admin that are made easy to customise. Your best bet is to override the admin's `changelist_view` method - unfortunately, there's a lot of logic in there, and you'll need to copy all that over just to override the bit you want to change. Look in django.contrib.admin.options for the code. -- DR. -- 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.