So I’m starting a django web application and I’m new using django… So please be patient with me. So, in my project I have two views: 1- a user profile; 2- a sort of a calculator, that can give several results at the same time according to the user input
So, to start, here is my model.py:
class Calanalisis(models.Model):
sequence = models.CharField(max_length=120000)
gc_content = models.DecimalField(decimal_places=3, max_digits=1000)
def gc_content_cal(self):
if self.sequence == True:
gc_content= round((self.sequence.count('C') +
self.sequence.count('G'))/len(self.sequence) * 100,1)
return gc_content
forms.py:
class AddSequenceForm(forms.ModelForm):
class Meta:
model = Calanalisis
fields = (‘sequence’,)
views.py:
def calc_sequence(request):
sequence_items=Calanalisis.objects.filter(person_of=request.user)
form=AddSequenceForm(request.POST)
if request.method=='POST':
form=AddSequenceForm(request.POST)
if form.is_valid():
profile=form.save(commit=False)
profile.person_of = request.user
profile.save()
return redirect('calc_sequence')
else:
form=AddSequenceForm()
myFilter=SequenceFilter(request.GET,queryset=sequence_items)
sequence_items=myFilter.qs
context = {'form':form,'sequence_items':sequence_items,'myFilter':myFilter}
return render(request, 'Add_Calc.html', context)
And now I want to introduce gc_content_cal to be calculated in the table. When I introduce the sequence, the sequence appears in the table, however the gc_content_cal continues to be 0,
Can someone help me please?