int()参数必须是字符串,类似字节的对象或数字,而不是“设置”

时间:2019-01-29 20:50:46

标签: python django django-rest-framework djongo

我无法使用Djongo作为引擎在Django中设置ArrayReferenceField。我正在尝试建立一个数据库,该数据库存储具有与使用ArrayReferenceField生成该项目相关的技能的学生的项目。该表单是通过“管理页面”生成的,但是在单击“保存”时会生成以下错误。 This is the image of the input I give on the django admin page

TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“设置”

我调查了类似的问题,但没有一个能够回答我的问题。我什至尝试使用ManyToManyField代替它,并且给出了相同的错误。有人可以帮我解决这个问题。预先感谢。

myapp / models.py

enter code here

class Skill(models.Model):
    id = models.AutoField(primary_key = True)
    skills = models.CharField(max_length = 30)

    def __str__(self):
        return self.skills

class UserCredential(models.Model):
    first_name = models.CharField(max_length = 25)
    last_name = models.CharField(max_length = 25)
    email = models.EmailField()
    username = models.CharField(max_length = 50, unique = True)
    password = models.CharField(max_length = 25)
    skills = models.ArrayReferenceField(to=Skill , 
    on_delete=models.CASCADE)

class Project(models.Model):
    title = models.CharField(max_length = 100)
    user = models.ForeignKey(to=UserCredential , 
    on_delete=models.CASCADE)
    description = models.TextField()
    req_skills = models.ArrayReferenceField(to=Skill , 
    on_delete=models.CASCADE)

myapp / serializers.py

class ProjectSerializer(serializers.ModelSerializer):
    model = Project
    fields = "__all__"
    class Meta:
        ordering = ["title"]

class SkillSerializer(serializers.ModelSerializer):
    model = Skill
    fields = ('skills',)

myapp / views.py

class UserCredentialListCreateView(generics.ListCreateAPIView):
    queryset = UserCredential.objects.all()
    serializer_class = UserCredentialSerializer
    permission_classes = (IsAdminUser,)

class ProjectListCreateView(generics.ListCreateAPIView):
    queryset = Project.objects.all()
    serializer_class = ProjectSerializer
    permission_classes = (IsAdminUser,)

class SkillListCreateView(generics.ListCreateAPIView):
    queryset = Skill.objects.all()
    serializer_class = SkillSerializer
    permission_classes = (IsAdminUser,)

整个TraceBack:

Traceback (most recent call last):
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\core\handlers\base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\core\handlers\base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\contrib\admin\options.py", line 604, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\utils\decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\contrib\admin\sites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\contrib\admin\options.py", line 1636, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\utils\decorators.py", line 45, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\utils\decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\contrib\admin\options.py", line 1525, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\contrib\admin\options.py", line 1557, in _changeform_view
    form_validated = form.is_valid()
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\forms\forms.py", line 185, in is_valid
    return self.is_bound and not self.errors
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\forms\forms.py", line 180, in errors
    self.full_clean()
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\forms\forms.py", line 383, in full_clean
    self._post_clean()
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\forms\models.py", line 403, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\base.py", line 1130, in full_clean
    self.clean_fields(exclude=exclude)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\base.py", line 1172, in clean_fields
    setattr(self, f.attname, f.clean(raw_value, self))
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\fields\__init__.py", line 631, in clean
    self.validate(value, model_instance)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\fields\related.py", line 903, in validate
    **{self.remote_field.field_name: value}
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\query.py", line 844, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\query.py", line 862, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\sql\query.py", line 1263, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\sql\query.py", line 1287, in _add_q
    split_subq=split_subq,
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\sql\query.py", line 1225, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\sql\query.py", line 1096, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\lookups.py", line 20, in __init__
    self.rhs = self.get_prep_lookup()
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\lookups.py", line 70, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "C:\Users\Bharat\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1.1-py3.6.egg\django\db\models\fields\__init__.py", line 965, in get_prep_value
    return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'set'


0 个答案:

没有答案