diff --git a/article/admin.py b/article/admin.py index f961d887..94a892a3 100644 --- a/article/admin.py +++ b/article/admin.py @@ -156,9 +156,12 @@ class BlogView(FormView): article = self.obj data = {} data['theme'] = [item.id for item in article.theme.all()] - data['exposition'] = article.exposition + if article.exposition: + data['exposition'] = article.exposition.id + if article.conference: + data['conference'] = article.conference.id + data['publish_date'] = article.publish_date - data['conference'] = article.conference a = ','.join(['%s:%s'%(item.id, item.name) for item in article.tag.all()]) data['tag'] = ','.join(['%s:%s'%(item.id, item.name) for item in article.tag.all()]) @@ -172,7 +175,12 @@ class BlogView(FormView): data['descriptions_%s' % code] = obj.descriptions form = form_class(data) #form.fields['tag'].widget.attrs['data-init-text'] = [item.name for item in article.tag.all()] - return form_class(data) + if article.exposition: + form.fields['exposition'].widget.attrs['data-init-text'] = article.exposition.name + if article.conference: + form.fields['conference'].widget.attrs['data-init-text'] = article.conference.name + + return form else: return form_class() diff --git a/article/forms.py b/article/forms.py index 5c44439d..0093baa0 100644 --- a/article/forms.py +++ b/article/forms.py @@ -90,8 +90,11 @@ class BlogForm(forms.Form): class NewsForm(BlogForm): type = Article.news - exposition = forms.ModelChoiceField(label = u'Выставка', required=False, queryset=Exposition.objects.all()) - conference = forms.ModelChoiceField(label = u'Конференция', required=False, queryset=Conference.objects.all()) + exposition = forms.CharField(label=u'Выставка', widget=forms.HiddenInput(), required=False) + conference = forms.CharField(label=u'Конференция', widget=forms.HiddenInput(), required=False) + + #exposition = forms.ModelChoiceField(label = u'Выставка', required=False, queryset=Exposition.objects.all()) + #conference = forms.ModelChoiceField(label = u'Конференция', required=False, queryset=Conference.objects.all()) def save(self, author, article=None): article = super(NewsForm, self).save(author, article) @@ -102,6 +105,24 @@ class NewsForm(BlogForm): article.save() return article + def clean_exposition(self): + id = self.cleaned_data['exposition'] + if not id: + return None + try: + return Exposition.objects.get(id=id) + except Exposition.DoesNotExist: + return None + + def clean_conference(self): + id = self.cleaned_data['conference'] + if not id: + return None + try: + return Conference.objects.get(id=id) + except Conference.DoesNotExist: + return None + class ArticleForm(forms.Form): """ Create Article form for creating conference diff --git a/templates/admin/article/blog_form.html b/templates/admin/article/blog_form.html index dd94d948..16a15c83 100644 --- a/templates/admin/article/blog_form.html +++ b/templates/admin/article/blog_form.html @@ -154,4 +154,46 @@ {% include 'admin/includes/file_form.html' with file_form=file_form object=article %} +{% endblock %} + + +{% block bot_scripts %} + {% endblock %} \ No newline at end of file