I've added a method highlight_link
to my model's admin.py class:
class RadioGridAdmin(admin.ModelAdmin): list_display = ('start_time', highlight_link) def highlight_link(self): return ('some custom link') admin.site.register(RadioGrid, RadioGridAdmin)
It returns a custom link for (I've left out highlight_link.short_description
for brevity) each record returned in the change list. Which is great. But I'd like to inspect the current query string and change the custom link based on that. Is there a way to access the request object within highlight_link
?
To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).
One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.
Test the 'view' permission is added to all modelsUsing #3 for Django 1.7 only creates the permission objects if the model doesn't already exist. Is there a way to create a migration (or something else) to create the permission objects for existing models?
The admin.py file is used to display your models in the Django admin panel. You can also customize your admin panel. Hope this helps you.
I solve my issue this way.
class MyClassAdmin(admin.ModelAdmin): def queryset(self, request): qs = super(MyClassAdmin, self).queryset(request) self.request = request return qs
Now i can use self.request
in any place
UPDATE
Changed in Django 1.6: The get_queryset method was previously named queryset.
class MyClassAdmin(admin.ModelAdmin): def get_queryset(self, request): qs = super(MyClassAdmin, self).get_queryset(request) self.request = request return qs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With