Autofill django summernote





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am submitting a form with summernote widget .



My forms.py:



 from django import forms
from .models import Task,Images
from django_summernote.widgets import SummernoteWidget

class StudentTaskForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={'class':
'form-control',' type': "text",'placeholder':'Enter Title'}))
content = forms.CharField(widget=SummernoteWidget())


class Meta:
model = Task
fields = [
'title',
'content',

]
widgets = {
'content': SummernoteWidget(),
}

def clean_object(self):
instance = self.instance

class ImageForm(forms.ModelForm):
image = forms.ImageField(label='Image')
class Meta:
model = Images
fields = ('image', )


The ImageForm is a formset part of this Taskform and the form submission is happening successfully. I want the user to be able to edit a task if the task already exists. For this i want the summernote widget to prepopulate with the previously entered data (title,content,images).ANy way i can implement this?



In my views i have :



@login_required(login_url='/account/login/')
def TaskCreateView(request,pk,todo_id):
if not request.user.is_authenticated:
return redirect('accounts:index')
elif User.objects.filter(pk=request.user.pk,
mentor__isnull=True).exists():
instance = get_object_or_404(Level, pk=pk)
sweetify.error(request, 'You have not added a trainer yet')


return HttpResponseRedirect(instance.get_absolute_url())
else :
instance = get_object_or_404(Level, pk=pk)
qs = instance.todo_set.get(id=todo_id)

todo = Task.objects.filter(todo=qs, student=request.user)
print("TODOS",todo)
verification = Verification.objects
.filter(task__in=todo,is_accepted=True,is_rejected=False)
bug=False
for tod in todo:
if tod.is_verified==False:
bug=True
if todo.exists() and verification.exists():
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

elif bug==True:
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

form = StudentTaskForm(request.POST or None, request.FILES or None)

if form.is_valid():
form.instance.user = User.objects.get(id=request.user.id)

obj = form.save(commit=False)
obj.student = request.user
obj.todo = qs
obj.level = instance
obj.save()



ImageFormSet = inlineformset_factory(Task,Images,
form=ImageForm,min_num=0,
max_num=3,
validate_min=True,extra=3)

if request.method == 'POST':
formset = ImageFormSet(request.POST, request.FILES,
instance=obj)
if formset.is_valid():
formset.save()

return redirect('student:dashboard')
else:
formset = ImageFormSet(queryset=Images.objects.none())


context={
'form': form,
"qs": qs,
'todo':todo,
'formset': formset,
'verified': verification,
}


return render(request,'task_form.html',context)









share|improve this question

























  • Don't know this SummernoteWidget but in Django the task of populating inputs with object's data (in ModelForms) happens when you bind a form to an object's instance. You can check this link for more information, but maybe you should add your view code so we can help you better.

    – ivissani
    Nov 16 '18 at 13:32











  • ok sure @ivissani

    – Mohit Harshan
    Nov 16 '18 at 13:34











  • I figured it out!THanks @ivissani

    – Mohit Harshan
    Nov 16 '18 at 14:14


















0















I am submitting a form with summernote widget .



My forms.py:



 from django import forms
from .models import Task,Images
from django_summernote.widgets import SummernoteWidget

class StudentTaskForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={'class':
'form-control',' type': "text",'placeholder':'Enter Title'}))
content = forms.CharField(widget=SummernoteWidget())


class Meta:
model = Task
fields = [
'title',
'content',

]
widgets = {
'content': SummernoteWidget(),
}

def clean_object(self):
instance = self.instance

class ImageForm(forms.ModelForm):
image = forms.ImageField(label='Image')
class Meta:
model = Images
fields = ('image', )


The ImageForm is a formset part of this Taskform and the form submission is happening successfully. I want the user to be able to edit a task if the task already exists. For this i want the summernote widget to prepopulate with the previously entered data (title,content,images).ANy way i can implement this?



In my views i have :



@login_required(login_url='/account/login/')
def TaskCreateView(request,pk,todo_id):
if not request.user.is_authenticated:
return redirect('accounts:index')
elif User.objects.filter(pk=request.user.pk,
mentor__isnull=True).exists():
instance = get_object_or_404(Level, pk=pk)
sweetify.error(request, 'You have not added a trainer yet')


return HttpResponseRedirect(instance.get_absolute_url())
else :
instance = get_object_or_404(Level, pk=pk)
qs = instance.todo_set.get(id=todo_id)

todo = Task.objects.filter(todo=qs, student=request.user)
print("TODOS",todo)
verification = Verification.objects
.filter(task__in=todo,is_accepted=True,is_rejected=False)
bug=False
for tod in todo:
if tod.is_verified==False:
bug=True
if todo.exists() and verification.exists():
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

elif bug==True:
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

form = StudentTaskForm(request.POST or None, request.FILES or None)

if form.is_valid():
form.instance.user = User.objects.get(id=request.user.id)

obj = form.save(commit=False)
obj.student = request.user
obj.todo = qs
obj.level = instance
obj.save()



ImageFormSet = inlineformset_factory(Task,Images,
form=ImageForm,min_num=0,
max_num=3,
validate_min=True,extra=3)

if request.method == 'POST':
formset = ImageFormSet(request.POST, request.FILES,
instance=obj)
if formset.is_valid():
formset.save()

return redirect('student:dashboard')
else:
formset = ImageFormSet(queryset=Images.objects.none())


context={
'form': form,
"qs": qs,
'todo':todo,
'formset': formset,
'verified': verification,
}


return render(request,'task_form.html',context)









share|improve this question

























  • Don't know this SummernoteWidget but in Django the task of populating inputs with object's data (in ModelForms) happens when you bind a form to an object's instance. You can check this link for more information, but maybe you should add your view code so we can help you better.

    – ivissani
    Nov 16 '18 at 13:32











  • ok sure @ivissani

    – Mohit Harshan
    Nov 16 '18 at 13:34











  • I figured it out!THanks @ivissani

    – Mohit Harshan
    Nov 16 '18 at 14:14














0












0








0








I am submitting a form with summernote widget .



My forms.py:



 from django import forms
from .models import Task,Images
from django_summernote.widgets import SummernoteWidget

class StudentTaskForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={'class':
'form-control',' type': "text",'placeholder':'Enter Title'}))
content = forms.CharField(widget=SummernoteWidget())


class Meta:
model = Task
fields = [
'title',
'content',

]
widgets = {
'content': SummernoteWidget(),
}

def clean_object(self):
instance = self.instance

class ImageForm(forms.ModelForm):
image = forms.ImageField(label='Image')
class Meta:
model = Images
fields = ('image', )


The ImageForm is a formset part of this Taskform and the form submission is happening successfully. I want the user to be able to edit a task if the task already exists. For this i want the summernote widget to prepopulate with the previously entered data (title,content,images).ANy way i can implement this?



In my views i have :



@login_required(login_url='/account/login/')
def TaskCreateView(request,pk,todo_id):
if not request.user.is_authenticated:
return redirect('accounts:index')
elif User.objects.filter(pk=request.user.pk,
mentor__isnull=True).exists():
instance = get_object_or_404(Level, pk=pk)
sweetify.error(request, 'You have not added a trainer yet')


return HttpResponseRedirect(instance.get_absolute_url())
else :
instance = get_object_or_404(Level, pk=pk)
qs = instance.todo_set.get(id=todo_id)

todo = Task.objects.filter(todo=qs, student=request.user)
print("TODOS",todo)
verification = Verification.objects
.filter(task__in=todo,is_accepted=True,is_rejected=False)
bug=False
for tod in todo:
if tod.is_verified==False:
bug=True
if todo.exists() and verification.exists():
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

elif bug==True:
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

form = StudentTaskForm(request.POST or None, request.FILES or None)

if form.is_valid():
form.instance.user = User.objects.get(id=request.user.id)

obj = form.save(commit=False)
obj.student = request.user
obj.todo = qs
obj.level = instance
obj.save()



ImageFormSet = inlineformset_factory(Task,Images,
form=ImageForm,min_num=0,
max_num=3,
validate_min=True,extra=3)

if request.method == 'POST':
formset = ImageFormSet(request.POST, request.FILES,
instance=obj)
if formset.is_valid():
formset.save()

return redirect('student:dashboard')
else:
formset = ImageFormSet(queryset=Images.objects.none())


context={
'form': form,
"qs": qs,
'todo':todo,
'formset': formset,
'verified': verification,
}


return render(request,'task_form.html',context)









share|improve this question
















I am submitting a form with summernote widget .



My forms.py:



 from django import forms
from .models import Task,Images
from django_summernote.widgets import SummernoteWidget

class StudentTaskForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={'class':
'form-control',' type': "text",'placeholder':'Enter Title'}))
content = forms.CharField(widget=SummernoteWidget())


class Meta:
model = Task
fields = [
'title',
'content',

]
widgets = {
'content': SummernoteWidget(),
}

def clean_object(self):
instance = self.instance

class ImageForm(forms.ModelForm):
image = forms.ImageField(label='Image')
class Meta:
model = Images
fields = ('image', )


The ImageForm is a formset part of this Taskform and the form submission is happening successfully. I want the user to be able to edit a task if the task already exists. For this i want the summernote widget to prepopulate with the previously entered data (title,content,images).ANy way i can implement this?



In my views i have :



@login_required(login_url='/account/login/')
def TaskCreateView(request,pk,todo_id):
if not request.user.is_authenticated:
return redirect('accounts:index')
elif User.objects.filter(pk=request.user.pk,
mentor__isnull=True).exists():
instance = get_object_or_404(Level, pk=pk)
sweetify.error(request, 'You have not added a trainer yet')


return HttpResponseRedirect(instance.get_absolute_url())
else :
instance = get_object_or_404(Level, pk=pk)
qs = instance.todo_set.get(id=todo_id)

todo = Task.objects.filter(todo=qs, student=request.user)
print("TODOS",todo)
verification = Verification.objects
.filter(task__in=todo,is_accepted=True,is_rejected=False)
bug=False
for tod in todo:
if tod.is_verified==False:
bug=True
if todo.exists() and verification.exists():
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

elif bug==True:
messages.error(request, 'You already completed this task')
return redirect('student:level-detail', pk=instance.id)

form = StudentTaskForm(request.POST or None, request.FILES or None)

if form.is_valid():
form.instance.user = User.objects.get(id=request.user.id)

obj = form.save(commit=False)
obj.student = request.user
obj.todo = qs
obj.level = instance
obj.save()



ImageFormSet = inlineformset_factory(Task,Images,
form=ImageForm,min_num=0,
max_num=3,
validate_min=True,extra=3)

if request.method == 'POST':
formset = ImageFormSet(request.POST, request.FILES,
instance=obj)
if formset.is_valid():
formset.save()

return redirect('student:dashboard')
else:
formset = ImageFormSet(queryset=Images.objects.none())


context={
'form': form,
"qs": qs,
'todo':todo,
'formset': formset,
'verified': verification,
}


return render(request,'task_form.html',context)






python django summernote






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 13:38







Mohit Harshan

















asked Nov 16 '18 at 13:20









Mohit HarshanMohit Harshan

478212




478212













  • Don't know this SummernoteWidget but in Django the task of populating inputs with object's data (in ModelForms) happens when you bind a form to an object's instance. You can check this link for more information, but maybe you should add your view code so we can help you better.

    – ivissani
    Nov 16 '18 at 13:32











  • ok sure @ivissani

    – Mohit Harshan
    Nov 16 '18 at 13:34











  • I figured it out!THanks @ivissani

    – Mohit Harshan
    Nov 16 '18 at 14:14



















  • Don't know this SummernoteWidget but in Django the task of populating inputs with object's data (in ModelForms) happens when you bind a form to an object's instance. You can check this link for more information, but maybe you should add your view code so we can help you better.

    – ivissani
    Nov 16 '18 at 13:32











  • ok sure @ivissani

    – Mohit Harshan
    Nov 16 '18 at 13:34











  • I figured it out!THanks @ivissani

    – Mohit Harshan
    Nov 16 '18 at 14:14

















Don't know this SummernoteWidget but in Django the task of populating inputs with object's data (in ModelForms) happens when you bind a form to an object's instance. You can check this link for more information, but maybe you should add your view code so we can help you better.

– ivissani
Nov 16 '18 at 13:32





Don't know this SummernoteWidget but in Django the task of populating inputs with object's data (in ModelForms) happens when you bind a form to an object's instance. You can check this link for more information, but maybe you should add your view code so we can help you better.

– ivissani
Nov 16 '18 at 13:32













ok sure @ivissani

– Mohit Harshan
Nov 16 '18 at 13:34





ok sure @ivissani

– Mohit Harshan
Nov 16 '18 at 13:34













I figured it out!THanks @ivissani

– Mohit Harshan
Nov 16 '18 at 14:14





I figured it out!THanks @ivissani

– Mohit Harshan
Nov 16 '18 at 14:14












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338729%2fautofill-django-summernote%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338729%2fautofill-django-summernote%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown