You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It will be nice to have, in optionnal, an icon associate for each message.
This icon will be associate to a status like "question", "info", "error", "resolved", ...
The text was updated successfully, but these errors were encountered:
frompybb.formsimportPostFormfrom .modelsimportTopicExtenderclassExtendedTopicForm(PostForm):
def__init__(self, *args, **kwargs):
super(ExtendedTopicForm, self).__init__(*args, **kwargs)
ifnotself.topicandself.forum:
self.is_new_topic=True# add you new fields heredefsave(self, commit=True):
super(ExtendedTopicForm, self).save(commit)
ifself.is_new_topic:
self.topic_extender=TopicExtender(topic=self.topic)
# assign your data hereifcommit:
self.topic_extender.save()
In your views.py :
frompybb.viewsimportAddPostViewfrom .formsimportExtendedTopicFormclassExtendedAddPostView(AddPostView):
post_form_class=ExtendedTopicFormdefform_valid(self, form):
response=super(ExtendedAddPostView, self).form_valid(form)
# currently, you must check if response is a success (redirect) because # form.save(commit=True) is not called in the super. So you must save your instance here.# Maybe we could add a `save_instances` method in `AddPostView` to make # this type of code easierifhasattr(form, 'topic_extender') andisinstance(response, HttpResponseRedirect):
topic_extender.save()
returnresponse
In your project's url.py, override the add_topic URL to use your own view.
If someone want to test this and create a PR to add this example in the doc, I think it would be useful for people. What do you think about it @lampslave and @skolsuper ?
It will be nice to have, in optionnal, an icon associate for each message.
This icon will be associate to a status like "question", "info", "error", "resolved", ...
The text was updated successfully, but these errors were encountered: