2016-06-14 43 views
0

尝试从我的model.py中的两个独立类获取几个字段输入。models.py中的不同类的不同字段 - TypeError:“元组”对象不可调用

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

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) 
+0

我可以看到的一个问题是,在创建clean_ 方法时需要返回一个值,请看这里:https://docs.djangoproject.com/en/1.9/ref/forms/validation/#form-and-现场验证 – ishikun

+0

现在,那些干净的方法不会做任何事情 – ishikun

+0

@ishikun Thnx!我会为此努力。 –

回答

0

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

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

+0

感谢您的回答。是的,我意识到,通过反复试验。我对python&django很新。关于如何解决这种情况的任何建议,以便我可以接收两个不同类别的输入和使用字段? –

+0

你需要两个班吗? – ishikun