0

我一直在这里搜索,发现一些与我有相同错误的东西,但我看不到任何与我的问题相似的东西,而不是标题,我敢肯定这是很愚蠢的,但我是 python 新手和找不到如何解决它。

模型.py

# -*- coding:utf-8 -*-

from django.db import models
from django_localflavor_br.br_states import STATE_CHOICES

""" 
Responsável pelo cadastro de novos profissionais de saúde no sistema(usuários).

"""

""" Usuários """
class Usuarios(models.Model):

    """ Formações da área de saúde disponíveis no momento no sistema """
    OPCAO_FORMACAO = (
        ('Medicina', '1'),
        ('Odontologia', '2'),
    )

    """ Informações de registro """
    created_at = models.DateTimeField(auto_now_add = True)
    # updated_at = models.DateTimeField(auto_now = True)

    """ Informações pessoais """
    nome = models.CharField(max_length=30)
    sobrenome = models.CharField(max_length=60)
    data_nascimento = models.DateField('Data de nascimento', blank=True)
    email = models.CharField('E-mail', max_length=80)

    """ Informações documentais """
    rg = models.IntegerField(blank=True)
    cpf = models.IntegerField(blank=True)

    formacao = models.ManyToManyField(max_length=20, choices=OPCAO_FORMACAO)
    registro = models.IntegerField(blank=True) # numero de registro do profissional
    estado_registro = models.ManyToManyField('Estado', max_length=2, choices=STATE_CHOICES)

    """ Informações extras """


    def __unicode__(self):
        return self.nome

错误

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x2b16350>>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 93, in inner_run
    self.validate(display_num_errors=True)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 166, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 72, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/lucas/Documentos/Django/saude/usuarios_registro/models.py", line 12, in <module>
    class Usuarios(models.Model):
  File "/home/lucas/Documentos/Django/saude/usuarios_registro/models.py", line 34, in Usuarios
    formacao = models.ManyToManyField(max_length=20, choices=OPCAO_FORMACAO)
TypeError: __init__() takes exactly 2 arguments (1 given)
4

1 回答 1

0

回溯包含有错误的行:

formacao = models.ManyToManyField(max_length=20, choices=OPCAO_FORMACAO)

如果您阅读了 ManyToManyFields 的 Django 文档,您会注意到它们使用了不同的选项。您要么需要创建formacao一个 CharField,要么创建一个可以正确关联的新模型。

于 2013-11-03T06:18:33.950 回答