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 7926199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:39:57+00:00 2026-06-03T18:39:57+00:00

I have a working django-admin custom command that I use to populate my database

  • 0

I have a working django-admin custom command that I use to populate my database with new information. Again, everything works.

However, I have now changed my models and function slightly to accept two arguments as a tuple – first name and last name, instead of just “name”.

Previous code below – working. Run using “manage.py xyz name1 name2 name3… etc. (space between the different args)

from django.core.management.base import BaseCommand, CommandError
from detail.models import ABC
from detail.parser import DEF

class Command(BaseCommand):
    args = '<name...>'
    help = 'Populates the ABC class database'

    def handle(self, *args, **options):
        for symbol in args:

            try:
                info = DEF(name)

Is it possible to pass on two arguments from the django-admin custom command where the second argument is optional –> i.e. (first, last=None)?

Pseudocode below of what I’d like to run using… “manage.py xyz (first1, last1) (first2, last2) <– or some variation of this

I’ve already changed the function DEF to accept this appropriately as a standalone function. I’m just not sure how I can get the django-admin command working now.

  • 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-03T18:40:01+00:00Added an answer on June 3, 2026 at 6:40 pm

    It’s entirely possible, although django.core.management does not provide a specific tool to do so. You can parse the arguments passed via the args keyword argument. You’ll have to come up with a syntax for doing so (defining the syntax in the help attribute of the command would probably be a good idea).

    Assuming the syntax is firstname.lastname, or just firstname in the case that the last name is omitted, you can do something like:

    def handle(self, *args, **options):
        for arg in args:
            try:
                first_name, last_name = arg.split('.')
            except ValueError:
                first_name, last_name = arg, None
    
            info = DEF(first_name, last_name)
    

    And users of the command can pass in arguments like so:

    $ python manage.py yourcommand -v=3 john.doe bill patrick.bateman
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django project that I have been working on as a solo
I have a project that I am working on in django. There are a
I'm following the Django-CMS introductory tutorial and have got everything working up to the
I need to have an at-home project now that I'm working on Python/Django at
I have a small app I'm working on where I'm trying to use Django's
Given that django-nonrel has got JOINs working, does this mean we have M2M fields
I'm working on a Django project, and I've created some custom admin views using
I am working through the examples in a Django book that I have, but
I have got tinyMCE working in the django admin, but all the popups are
I have created a site mainly using django's admin interface, plus a few custom

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.