Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:40:56+00:00 2026-06-10T16:40:56+00:00

Referring to, executing management commands from code , Is their a way to call

  • 0

Referring to, executing management commands from code,

Is their a way to call this command execution code from the django admin interface?

I’ve a custom command to do some periodic update of database which has been scheduled as cron. The cron is working fine. I need to update the database manually from the admin interface whenever needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:40:58+00:00Added an answer on June 10, 2026 at 4:40 pm

    update: you can run any management command simply by calling the function call_command('compilemessages') from anywhere within your python code. Note: this obviously is a blocking process from the caller’s perspective. With the ajax example below you can have a form of non-blocking/asynchronous user experience. Depending on the backend implementation you can take this isolation level further.

    Example:

    from django.core.management import call_command
    call_command('compilemessages')
    

    If the task is bound to the object currently viewed in the admin, a nice way might be to implement an extra view called by an ajax script when clicking a button. The extra view could optionally be wrapped as a celery task, e.g.

    models.py

    class Foo(models.Model):
        # fields...
    
        def my_task_init(self):
            return mark_safe("<img class='loading' src='/static/img/loading.gif' alt='loading' style='display:none;' /><a data-identifier='task_%i' class='task'><img src='/static/img/process.png' style='cursor:pointer;' /></a>") % self.id
        my_task_init.allow_tags = True
        my_task_init.short_description = _(u"Execute Task")
    

    admin.py

    class FooAdmin(admin.ModelAdmin):
        list_display = ['other_field', 'my_task_init']
    
        class Media:
            js = (
                'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js',
                '/static/js/admin_tasks.js',
            )
    
        def get_urls(self):
            urls = super(FooAdmin, self).get_urls()
            extra_urls = patterns('',
                (r'^my-task/$', self.admin_site.admin_view(self.parse_view))
            )
            return extra_urls + urls
    
        # optionally decorated by celery
        def task_view(self, request):
            if not request.is_ajax():
                raise Http404
            task_id = request.GET.get('task_id')
            # your logic
            return HttpResponse('Success')
    

    admin_tasks.js

    $(document).ready(function (){
       $('.task').click(function(){
           var image = $(this).find('img'),
               loading = $(this).parent().find('.loading'),
               task_id = $(this).data('identifier').replace('task_', '');
           $.ajax({
               type: "GET",
               data: ({'task_id': task_id}),
               url: "/admin/app/model/my-task/",
               beforeSend: function() {
                   image.hide();
                   loading.show();
               },
               statusCode: {
                   200: function() {
                       loading.hide();
                       image.attr('src', '/static/img/success.png');
                       image.show();
                   },
                   404: function() {
                       loading.hide();
                       image.attr('src', '/static/img/error.png');
                       image.show();
                   },
                   500: function() {
                       loading.hide();
                       image.attr('src', '/static/img/error.png');
                       image.show();
                   }
               }
           });
       });
    });
    

    If you’re trying to initiate an unbound task you could just override a template element or add some html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Referring back to this SO post If there is a Grouping category Category which,
Referring to the other question I asked Django using AJAX with Forms, Views ,
Referring to this question , how can i get the current page size in
referring to this question , I've decided to duplicate the tables every year, creating
Referring to the Configuration Manager under the Build menu, Is there a way to
Referring to What is the correct way to make a custom .NET Exception serializable?
When looking at the actual execution plan for a query in SQL Server Management
Referring to this question, let's say we have the following scenario - A model
Is the execution time (run-time) performance of code in a class that is loaded
I'm wondering what would be the correct approach after executing a command that allocates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.