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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:52:08+00:00 2026-06-04T16:52:08+00:00

I am aware that when using MyModel.objects.create in Django, it is possible to pass

  • 0

I am aware that when using MyModel.objects.create in Django, it is possible to pass in a dictionary with keys which correspond to the model fields in MyModel. This is explained in another question here: Can a dictionary be passed to django models on create?

However, I am trying to pass in a dictionary which has more keys than there are model fields – in other words, some of the keys are not used in the creation of the object. Is it possible to do this in some way? For example:

data_dict = {
    'key1': value1,
    'key2': value2,
    'key3': value3,
}

class MyModel(models.Model):
    key1 = models.SomeField()
    key2 = models.SomeField()

m = MyModel.objects.create(**data_dict)

When I try this, I get an error telling me that “‘key3’ is an invalid keyword argument for this function”. Am I passing the dictionary in incorrectly? Is there a different way to pass it to the model that means the model doesn’t have to use all of the arguments? Or will I simply have to specify each field manually like this:

m = MyModel.objects.create(
    key1 = data_dict['key1'],
    key2 = data_dict['key2'],
)
  • 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-04T16:52:09+00:00Added an answer on June 4, 2026 at 4:52 pm

    You can filter, then pass your dictionary this way:

    MyModel.objects.create(**{key: value for key, value in data_dict.iteritems() if key in MyModel._meta.get_all_field_names()}).

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

Sidebar

Related Questions

I am aware that using setters in dealloc can create problems, if any other
I am aware that you can 'remotely' script android using port forwarding, using the
I am aware that I can access all external links on a page using
I'm trying to find eveything inside a div using regexp. I'm aware that there
I aware that Java object constructors implicitly initialize their instance's non-static fields. However, I'm
I'm aware that using /USER_ID/feed on a API call, you can write to this
I am aware that using CSS sprites is the way to go when you
I am aware that a CALayer's shadowPath is only animatable using explicit animations, however
I am aware that using proxy capable libraries (javassist, JDK dynamic proxies, etc) that
Good day, I would like to know if that's possible using RegExp and if

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.