Testing custom admin actions in django

Just pass the parameter action with the action name. response = client.post(change_url, {‘action’: ‘mark_as_read’, …}) Checked items are passed as _selected_action parameter. So code will be like this: fixtures = [MyModel.objects.create(read=False), MyModel.objects.create(read=True)] should_be_untouched = MyModel.objects.create(read=False) #note the unicode() call below data = {‘action’: ‘mark_as_read’, ‘_selected_action’: [unicode(f.pk) for f in fixtures]} response = client.post(change_url, data)

How to set initial data for Django admin model add instance form?

Alasdair’s approach is nice but outdated. Radev’s approach looks quite nice and as mentioned in the comment, it strikes me that there is nothing about this in the documentation. Apart from those, since Django 1.7 there is a function get_changeform_initial_data in ModelAdmin that sets initial form values: def get_changeform_initial_data(self, request): return {‘name’: ‘custom_initial_value’}

How to set “Run this program as an administrator” programmatically

You can programmatically set the “Run this program as an administrator” flag (the option you find in the Compatibility tab of an EXE’s properties), by setting a simple registry key. You need to create a string value (REG_SZ) under one of these keys (if you want the setting to be per user or per machine, … Read more

is it possible to create a custom admin view without a model behind it

hmmm. Thanks for your help everyone. The solution I have come up ( with your help ofcourse 🙂 is as follows: I have two custom templates: my_model_list.html my_model_detail.html Under views.py: class MyModel(object): # … Access other models # … process / normalise data # … store data @staff_member_required def my_model_list_view(request) #show list of all objects … Read more

Adding a jQuery script to the Django admin interface

To add media to the admin you can simply add it to the meta class Media of your admin class, e.g.: admin.py class FooAdmin(admin.ModelAdmin): # regular stuff class Media: js = ( ‘//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js’, # jquery ‘js/myscript.js’, # project static folder ‘app/js/myscript.js’, # app static folder ) admin.site.register(Foo, FooAdmin) Mind the trailing comma if you only … Read more

Java: run as administrator

You have to create a manifest file that specifies that your application needs administrator permissions. You can include the manifest in your exe or keep it as a separate file (yourapp.exe.manifest) http://msdn.microsoft.com/en-us/library/bb756929.aspx

Prevent django admin from escaping html

As of Django 1.9, you can use format_html(), format_html_join(), or allow_tags in your method. See the list_display docs for more info. The code in the question using mark_safe will work. However a better option for methods like these might be format_html, which will escape arguments. def _get_thumbnail(self, obj): return format_html(u'<img src=”{}” />’, obj.admin_thumbnail.url) In earlier … Read more