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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:16:06+00:00 2026-06-13T14:16:06+00:00

I have a models.py like so: from django.db import models from django.contrib.auth.models import User

  • 0

I have a models.py like so:

from django.db import models
from django.contrib.auth.models import User
from datetime import datetime


class UserProfile(models.Model):
    user = models.OneToOneField(User)

    def __unicode__(self):
        return self.user.username


class Project(models.Model):
    user = models.ForeignKey(UserProfile)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    product = models.ForeignKey('tool.product')
    module = models.ForeignKey('tool.module')
    model = models.ForeignKey('tool.model')
    zipcode = models.IntegerField(max_length=5)

    def __unicode__(self):
        return unicode(self.id)

And my tests.py:

from django.test import TestCase, Client
# --- import app models
from django.contrib.auth.models import User
from tool.models import Module, Model, Product
from user_profile.models import Project, UserProfile


# --- unit tests --- #
class UserProjectTests(TestCase):

    fixtures = ['admin_user.json']

    def setUp(self):
        self.product1 = Product.objects.create(
            name='bar',
        )
        self.module1 = Module.objects.create(
            name='foo',
            enable=True
        )
        self.model1 = Model.objects.create(
            module=self.module1,
            name='baz',
            enable=True
        )
        self.user1 = User.objects.get(pk=1)

    ...

    def test_can_create_project(self):
        self.project1 = Model.objects.create(
            user=self.user1,
            product=self.product1,
            module=self.module1,
            model=self.model1,
            zipcode=90210
        )

        self.assertEquals(self.project1.zipcode, 90210)

But I get a TypeError: 'product' is an invalid keyword argument for this function error.

I’m not sure what is failing but I’m guessing something to do with the FK relationships…

Any help would be much appreciated.

EDIT:
Full Traceback:

    ERROR: test_can_create_project (user_profile.tests.UserProjectTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/Dropbox/django-projects/unirac/user_profile/tests.py", line 52, in test_can_create_project
    zipcode=90210
  File "/home/sam/.envs/unirac/local/lib/python2.7/site-packages/django/db/models/manager.py", line 137, in create
    return self.get_query_set().create(**kwargs)
  File "/home/sam/.envs/unirac/local/lib/python2.7/site-packages/django/db/models/query.py", line 375, in create
    obj = self.model(**kwargs)
  File "/home/sam/.envs/unirac/local/lib/python2.7/site-packages/django/db/models/base.py", line 367, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
TypeError: 'product' is an invalid keyword argument for this function
  • 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-13T14:16:07+00:00Added an answer on June 13, 2026 at 2:16 pm

    Model.objects.create(… should likely be Project.objects.create(

    At:

    self.project1 = Model.objects.create(
        user=self.user1,
        product=self.product1,
        module=self.module1,
        model=self.model1,
        zipcode=90210
    )
    

    On a sidenote, naming your Model, Model, as from tool.models import Module, Model, Product seems to imply, is a bad idea.


    On another sidenote, the traceback usually provides very useful information as to where the error occured. Here, you can see that the traceback indicates the error occured in:

    File "/home/sam/Dropbox/django-projects/unirac/user_profile/tests.py", line 52, in test_can_create_project
    

    Before jumping to library code, which you can reasonably expect to not be buggy.

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

Sidebar

Related Questions

I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have a form like so: from django import forms from django.contrib.auth.models import User
I have a model that looks like this: from django.db import models from django.contrib.auth.models
Currently I have the from django.contrib.auth.models import User but I'm confused as to how
Given this model: from django.db import models from django.contrib.auth.admin import User # Create your
Initially, I started my UserProfile like this: from django.db import models from django.contrib.auth.models import
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
I want a nice convenient attribute to do the following: from django.contrib.auth.models import User
So I can create Django model like this: from django.db import models class Something(models.Model):
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):

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.