私は次のようなモデルを持っています:
from django.db import models
from django.contrib.auth.models import User
class Skill(models.Model):
title = models.CharField(max_length=255)
def __unicode__(self):
return self.title
class UserSkills(models.Model):
user = models.ForeignKey(User)
skill = models.ForeignKey(Skill)
def __unicode__(self):
return '%s | %s' % (self.user, self.skill)
私がこれをしようとすると:
>>> u = User.objects.get(username='myuser')
>>> s, created = Skill.objects.get_or_create(title='mysql')
>>> type(u)
<class 'django.contrib.auth.models.User'>
>>> type(s)
<class 'django_myapp.models.Skill'>
>>> userskill, created = UserSkills.objects.get_or_create(skill=s, user=u)
TypeError: 'skill' is an invalid keyword argument for this function
ここで何が間違っていますか?
余談ですが、私のUserSkills
モデルは余分かもしれないと感じています。それは単にモデルのManyToMany
フィールドでSkill
ある必要がありUser
ますか?
編集
トレースバック:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/sam/.envs/rs-open-auth/local/lib/python2.7/site-packages/django/db/models/manager.py", line 149, in create
return self.get_query_set().create(**kwargs)
File "/home/sam/.envs/rs-open-auth/local/lib/python2.7/site-packages/django/db/models/query.py", line 414, in create
obj = self.model(**kwargs)
File "/home/sam/.envs/rs-open-auth/local/lib/python2.7/site-packages/django/db/models/base.py", line 415, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])