Итак, я начинаю переключать модели моделей на базовые виды классов. В EpisodeInfoView
, когда я комментирую или раскомментирую production = Production.objects.create(podcast=podcast)
под if podcast
в моем методе get
в pod_funnel.py
, он отобразит форму и позвольте мне заполнить поля, но когда я зарегистрирую Productions
под администратором, он показывает, что создает производство под именем Podcast (который извлекается из его ForeignKey
) but without the rest of the info (episode number, episode guest, episode title, etc...) И если я удаляю и добавляю его для создания объекта в сообщении, он показывает мне форму, но ничего не делает и не показывает никаких ошибок.Django: поля ввода в поданной форме не отображаются
pod_funnel.py
вид:
class EpisodeInfoView(LoginRequiredMixin, View):
form_class = EpisodeInfoForm
template_name = 'pod_funnel/forms_episode_info.html'
def get(self, request, *args, **kwargs):
initial_values = {}
user = request.user
# Lets get client and podcast for the user already. if not existent raise 404
client, podcast = get_podfunnel_client_and_podcast_for_user(user)
if client is None or podcast is None:
raise Http404
if podcast:
initial_values['podcast_name'] = podcast.name
initial_values['podcast_id'] = podcast.id
production = Production.objects.filter(podcast=podcast).first()
# production = Production.objects.create(podcast=podcast)
if production:
initial_values['episode_number'] = production.episode_number
initial_values['episode_title'] = production.episode_title
initial_values['episode_guest_first_name'] = production.episode_guest_first_name
initial_values['episode_guest_last_name'] = production.episode_guest_last_name
initial_values['episode_guest_twitter_name'] = production.episode_guest_twitter_name
initial_values['episode_summary'] = production.episode_summary
form = self.form_class(initial=initial_values)
return render(request, self.template_name, {'form': form})
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
# lets get the data
# podcast_id = form.cleaned_data.get('podcast_id')
production_id = form.cleaned_data.get('production_id')
episode_number = form.cleaned_data.get('episode_number')
episode_title = form.cleaned_data.get('episode_title')
episode_guest_first_name = form.cleaned_data.get('episode_guest_first_name')
episode_guest_last_name = form.cleaned_data.get('episode_guest_last_name')
episode_guest_twitter_name = form.cleaned_data.get('episode_guest_twitter_name')
episode_summary = form.cleaned_data.get('episode_summary')
user = request.user
# Get the production
# podcast = get_object_or_404(Podcast, id=podcast_id)
production = get_object_or_404(Production, id=production_id)
# Lets see if we have client and podcast for the user already
client, podcast = get_podfunnel_client_and_podcast_for_user(user)
if production is None:
production = Production.objects.create(podcast=podcast)
production.episode_number = episode_number
production.episode_title = episode_title
production.episode_guest_first_name = episode_guest_first_name
production.episode_guest_last_name = episode_guest_last_name
production.episode_guest_twitter_name = episode_guest_twitter_name
production.episode_summary = episode_summary
production.save()
# TODO: Needs to redirect to next step
return HttpResponseRedirect(reverse('podfunnel:episodeimagefiles'))
return render(request, self.template_name, {'form': form})
episode_info.py
форма:
class EpisodeInfoForm(forms.Form):
podcast_name = forms.CharField(widget=forms.Field.hidden_widget, required=False, max_length=100, disabled=True)
podcast_id = forms.IntegerField(widget=forms.Field.hidden_widget)
production_id = forms.IntegerField(widget=forms.Field.hidden_widget, required=False)
id = forms.IntegerField(widget=forms.Field.hidden_widget)
episode_number = forms.IntegerField(widget=forms.NumberInput, required=True)
episode_title = forms.CharField(max_length=255, required=True)
episode_guest_first_name = forms.CharField(max_length=128)
episode_guest_last_name = forms.CharField(max_length=128)
episode_guest_twitter_name = forms.CharField(max_length=64)
episode_summary = forms.CharField(widget=forms.Textarea)
Вы можете включать в свой шаблон HTML? – fips