models.py中不同类的不同字段 - TypeError:' tuple'对象不可调用

时间:2016-06-14 22:09:32

标签: django django-models django-forms django-views tuples

尝试从model.py中的两个单独的类中获取几个字段输入。

目的是让用户输入以下内容:

First Name Last Name Podcast iTunes URL

当我尝试执行它时,我收到以下错误:

Environment:


Request Method: GET
Request URL: http://192.168.33.10:8000/podfunnel/clientsetup/

Django Version: 1.9
Python Version: 2.7.6
Installed Applications:
('producer',
 'django.contrib.admin',
 'django.contrib.sites',
 'registration',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions',
 'randomslugfield',
 'adminsortable2',
 'crispy_forms')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')



Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/generic/edit.py" in get
  212.         return self.render_to_response(self.get_context_data())

File "/usr/local/lib/python2.7/dist-packages/django/views/generic/edit.py" in get_context_data
  121.         kwargs.setdefault('form', self.get_form())

File "/usr/local/lib/python2.7/dist-packages/django/views/generic/edit.py" in get_form
  74.         return form_class(**self.get_form_kwargs())

Exception Type: TypeError at /podfunnel/clientsetup/
Exception Value: 'tuple' object is not callable

我试图将form_class = ClientSetupForm, PodcastSetupForm放在我的ClientSetupView括号内,但它仍然给我同样的错误。

感谢任何帮助。

这是我的views.py

from django.shortcuts import render

from .forms.client_setup import ClientSetupForm
from .forms.podcast_setup import PodcastSetupForm
from .forms.episode_info import EpisodeInfoForm
from .forms.image_files import EpisodeImageFilesForm
from .forms.wordpress_info import WordpressInfoForm
from .forms.chapter_marks import ChapterMarksForm
from .forms.show_links import ShowLinksForm
from .forms.tweetables import TweetablesForm
from .forms.clicktotweet import ClickToTweetForm
from .forms.schedule import ScheduleForm

from producer.models import Client, Production, ChapterMark, ProductionLink, ProductionTweet, Podcast

from django.views.generic.edit import FormView

class ClientSetupView(FormView):
    template_name = 'pod_funnel/forms.html'
    form_class = ClientSetupForm, PodcastSetupForm
    success_url = '/podfunnel/dashboard/'

    def form_valid(self, form):
        # here we create the Client and the Podcast for the user
        form.first_name()
        form.last_name()
        form.name()
        form.itunes_url()
        return super(ClientSetupView, self).form_valid(form)

# Create your views here.
def dashboard(request):

    if request.user.is_authenticated():

        # we make sure user has gone through setup process by making user it
        # has a client associated with it.
        # client = Client.objects.filter(user=request.user).first()
        # if client is None:
        #     # Trigger Step 2.
        #
        # else:
        #     podcast = Podcast.objects.filter(client=client).first()
        #     # trigget dashboard for podcast.

        #print(Client.objects.all())
        # i = 1
        # for instance in Client.objects.all():
        #   print(i)
        #   print(instance.full_name)
        #   i += 1

        queryset = Client.objects.all() #.filter(full_name__iexact="test3")
        #print(Client.objects.all().order_by('-timestamp').filter(full_name__iexact="test3").count())
        context = {
            "queryset": queryset
        }

        return render(request, "pod_funnel/dashboard.html", context)

client_setup.py

from django import forms

from producer.models import Client

class ClientSetupForm(forms.Form):

    first_name = forms.CharField()
    last_name = forms.CharField()

    def clean_first_name(self):
        first_name = self.cleaned_data.get('first_name')

        pass

    def clean_last_name(self):
        last_name = self.cleaned_data.get('last_name')

        pass

podcast_setup.py

from django import forms

from producer.models import Podcast

class PodcastSetupForm(forms.Form):

    name = forms.CharField()
    itunes_url = forms.URLField()

    def clean_name(self):
        name = self.cleaned_data.get('name')

        pass

    def clean_itunes_url(self):
        itunes_url = self.cleaned_data.get('itunes_url')

        pass

每个班级models.py

from django.db import models
from django.conf import settings
from django.utils.encoding import smart_text
from producer import myFields
from randomslugfield import RandomSlugField
from django.contrib.auth.models import User
from django.core import urlresolvers

class Client(TimeStampedModel):
    company_name = models.CharField(max_length=64)
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    email = models.EmailField()
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    def full_name(self):
        return smart_text('%s %s' % (self.first_name, self.last_name))

    def __unicode__(self):
        return smart_text(self.company_name)

class Podcast(TimeStampedModel):
    PRODUCTION_NAMES_HELP = 'You can use the following placeholders in the name: EPISODE_GUEST_FULL_NAME, ' \
                            'EPISODE_NUMBER, EPISODE_TITLE'

    BASE_PROD_DEFAULT_TITLE_FORMAT = 'EPISODE_NUMBER EPISODE_GUEST_FULL_NAME - EPISODE_TITLE'
    SECONDARY_PROD_DEFAULT_TITLE_FORMAT = 'EPISODE_TITLE with EPISODE_GUEST_FULL_NAME'

    client = models.ForeignKey(Client)
    name = models.CharField(max_length=100)
    uuid = models.CharField(max_length=32, verbose_name='Auphonic Preset UUID')

    dropbox_service = models.ForeignKey(Service, null=True, blank=True, related_name='dropbox_service_id',
                                        limit_choices_to={'provider': Service.DROPBOX}, on_delete=models.SET_NULL)
    soundcloud_service = models.ForeignKey(Service, null=True, blank=True, related_name='soundcloud_service_id',
                                           limit_choices_to={'provider': Service.SOUNDCLOUD}, on_delete=models.SET_NULL)
    libsyn_service = models.ForeignKey(Service, null=True, blank=True, related_name='libsyn_service_id',
                                       limit_choices_to={'provider': Service.LIBSYN}, on_delete=models.SET_NULL)
    archiveorg_service = models.ForeignKey(Service, null=True, blank=True, related_name='archiveorg_service_id',
                                           limit_choices_to={'provider': Service.ARCHIVEORG}, on_delete=models.SET_NULL)
    blubrry_service = models.ForeignKey(Service, null=True, blank=True, related_name='blubrry_service_id',
                                        limit_choices_to={'provider': Service.BLUBRRY}, on_delete=models.SET_NULL)
    youtube_service = models.ForeignKey(Service, null=True, blank=True, related_name='youtube_service_id',
                                        limit_choices_to={'provider': Service.YOUTUBE}, on_delete=models.SET_NULL)
    wordpress_config = models.ForeignKey(WordpressConfig, on_delete=models.SET_NULL, null=True, blank=True)

    itunes_url = models.URLField(null=True, blank=True)

    soundcloud_account = models.ForeignKey(SoundcloudConfig, on_delete=models.SET_NULL, null=True, blank=True)
    twitter_account = models.ForeignKey(TwitterConfig, on_delete=models.SET_NULL, null=True, blank=True)
    podcast_twitter_name = models.CharField(max_length=64, null=True)
    podcast_guest_twitter_name = models.CharField(max_length=64, null=True)
    schedule_tweets_on_publish = models.BooleanField(default=True, verbose_name="Schedule 'First Week Tweets' when "
                                                                                "production is published")
    podcast_click_to_tweet_format = models.CharField(max_length=200, null=True, blank=True,
                                                     help_text='You can use the following placeholders in the text: '
                                                               'PODCAST_TWITTER_NAME, PODCAST_GUEST_TWITTER_NAME, '
                                                               'WORDPRESS_URL')

    production_auto_email_test_mode = models.BooleanField(default=True, help_text='While Test Mode is enabled, Auto'
                                                                                  'email is sent to FullCast admin team'
                                                                                  'only. If disabled it will also be'
                                                                                  'sent to client email.')
    production_auto_email_subject_format = models.CharField(max_length=200, null=True, blank=True)
    production_auto_email_format = models.TextField(null=True, blank=True,
                                                    help_text='You can use the following placeholders in the text: '
                                                              'CLIENT_FIRST_NAME, WORDPRESS_URL, TRANSCRIPTION_URL, '
                                                              'EPISODE_GUEST_FIRST_NAME, EPISODE_GUEST_LAST_NAME, '
                                                              'EPISODE_NUMBER, CLICK_TO_TWEET_LINK, ITUNES_URL')

    base_production_name_format = models.CharField(max_length=200, null=True, blank=True,
                                                   default=BASE_PROD_DEFAULT_TITLE_FORMAT)
    secondary_production_name_format = models.CharField(max_length=200, null=True, blank=True,
                                                        default=SECONDARY_PROD_DEFAULT_TITLE_FORMAT,
                                                        help_text=PRODUCTION_NAMES_HELP)

    def __unicode__(self):
        return smart_text(self.name)

1 个答案:

答案 0 :(得分:0)

回溯显示出了什么问题。出于某种原因,您在视图的form_class属性中放了两个类:当您用逗号分隔两个对象时,会创建一个元组。

我不知道你在那里做什么,但你只能有一个表格。