Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:25:19+00:00 2026-06-14T08:25:19+00:00

models.py from django.db import models from django.contrib.auth.models import User from registeredmember.models import Registeredmember #

  • 0

models.py

from django.db import models
from django.contrib.auth.models import User

from registeredmember.models import Registeredmember


# Create your models here.

class Carloan_form(models.Model):
    cost_of_vehicle_Naira               = models.DecimalField(max_digits=10, decimal_places=2)
    loan_repayment_tenure_Months        = models.DecimalField(max_digits=10, decimal_places=2)
    interest_rate_Percentage            = models.DecimalField(max_digits=10, decimal_places=2)
    equity_contrib_rate_Percentage      = models.DecimalField(max_digits=10, decimal_places=2)
    depreciation_rate_Percentage        = models.DecimalField(max_digits=10, decimal_places=2)
    user                                = models.ForeignKey(User, null=True)
    time                                = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
            return unicode(self.user)    

forms.py

from django import forms
from django.forms import ModelForm

from models import Carloan_form

class Carloan_formForm(ModelForm):
    cost_of_vehicle_Naira           = forms.DecimalField(label=(u'Cost of vehicle (in Naira)'))
    loan_repayment_tenure_Months    = forms.DecimalField(label=(u'Loan tenure (in Months)'))
    interest_rate_Percentage        = forms.DecimalField(label=(u'Interest rate (in %)'))
    equity_contrib_rate_Percentage  = forms.DecimalField(label=(u'Equity contribution rate (in %)'))
    depreciation_rate_Percentage    = forms.DecimalField(label=(u'Depreciation rate (in %)'))
    class Meta:
        model = Carloan_form
        exclude = ('user',)

views.py

from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required


from forms import Carloan_formForm
@login_required
def index(request):
    form = Carloan_formForm()
    if request.POST:
        form = Carloan_formForm(request.POST)
        if form.is_valid():
            form.save()

            #Collection and Assignment of User input
            amount_of_vehicle = float(form.cleaned_data['cost_of_vehicle_Naira'])
            tenure = float(form.cleaned_data['loan_repayment_tenure_Months'])
            interest_rate = float(form.cleaned_data['interest_rate_Percentage'])
            equity = float(form.cleaned_data['equity_contrib_rate_Percentage'])
            depreciation_rate = float(form.cleaned_data['depreciation_rate_Percentage'])
            carloan = form.save(commit=False)
            carloan.user = request.user
            carloan.save()

            #Class Definition
            class LoanCalc:
                def __init__(self,amount_of_vehicle,tenure,interest_rate,equity,depreciation_rate):
                    self.amount_of_vehicle = amount_of_vehicle
                    self.tenure = tenure
                    self.interest_rate = interest_rate
                    self.equity = equity
                    self.depreciation_rate = depreciation_rate
                def interest(self):
                      return((self.interest_rate/100) * self.amount_of_vehicle *(self.tenure/12))
                def management_fee(self):
                    return 0.01 * (self.amount_of_vehicle + self.interest())
                def processing_fee(self):
                    return 0.0025 *(self.amount_of_vehicle + self.interest())
                def legal_fee(self):
                    return 0.0075 *(self.amount_of_vehicle + self.interest())
                def residual_amount(self):
                    return 0.01 * (self.amount_of_vehicle - ((self.depreciation_rate/100) * self.amount_of_vehicle *(self.tenure/12)))
                def equity_contribution(self):
                    return (self.equity/100) * self.amount_of_vehicle
                def total_amount(self):
                    return self.amount_of_vehicle+self.interest()+self.management_fee()+self.processing_fee()+self.legal_fee()+self.residual_amount() 
                def upfront_payment(self):
                    return self.management_fee() + self.processing_fee() + self.legal_fee() + self.equity_contribution() + self.residual_amount()
                def opening_balance(self):
                    return self.total_amount() - self.upfront_payment()
                def monthly_instalment(self):
                    return self.opening_balance()/self.tenure
                def LoanPaymentPlan(self):
                    months = 1
                    total_amount = self.amount_of_vehicle+self.interest()+self.management_fee()+self.processing_fee()+self.legal_fee()+self.residual_amount()
                    upfront_payment = self.management_fee()+self.processing_fee()+self.legal_fee()+self.equity_contribution()+self.residual_amount()
                    opening_balance = total_amount - upfront_payment
                    balance = opening_balance
                    while months <= self.tenure:
                        if balance > 0:
                            monthly_instalment =(opening_balance/self.tenure)
                            monthly_interest = (((self.interest_rate/100) * balance)/ 12)
                            loan_payment = monthly_instalment - monthly_interest
                            closing_balance = balance - monthly_instalment
                            print '  ',months,'  ',round(balance,2),'   ', round(monthly_instalment,2),'        ',round(monthly_interest,2) \
                            , '       ',' ',round(loan_payment,2),'     ',round(closing_balance,2)
                            balance = closing_balance
                            months += 1
                    return 'Thank you for using the Loan Calc App'

            #Creation of an instance with the name 'calc'
            calc = LoanCalc(amount_of_vehicle,tenure,interest_rate,equity,depreciation_rate)
            amountofVehicle = amount_of_vehicle
            interest = calc.interest()
            managementFee = calc.management_fee()
            processingFee = calc.processing_fee()
            legalFee = calc.legal_fee()
            residualAmount = calc.residual_amount()
            equityContribution = calc.equity_contribution()
            totalAmount = calc.total_amount()
            upfrontPayment = calc.upfront_payment()
            openingBalance = calc.opening_balance()
            loanpaymentplan =calc.LoanPaymentPlan()



            #An empty form to be displayed alongside the result
            forms = Carloan_formForm()

            #Renders a template that displays the result
            return render_to_response('carloan/result.html', {'form': forms, 'result':amountofVehicle , 'result1': interest, 'result2': managementFee, 'result3': processingFee,
                                                              'result4': legalFee, 'result5': residualAmount, 'result6': equityContribution, 'result7': totalAmount,
                                                              'result8': upfrontPayment, 'result9':openingBalance, 'result10': loanpaymentplan},
                          context_instance=RequestContext(request))
    #If the user doesn't submit the form, it displays an empty form
    else:
        form = Carloan_formForm()
    #Rendering a that template that displays an empty form
    return render_to_response('carloan/index.html', {'form': form},
                          context_instance=RequestContext(request))

My questions are;

  1. Is there a way i can save the results am passing to the template?
  2. Is there a way i can send the results that i have saved in Q1. above, and send it to the user through email(only when the user wants it)?

3.’result10′: loanpaymentplan` that i am passing to the template, only prints one line and doesn’t go through the loop and print everything but meanwhile it prints everything in the command prompt(still in development). What could be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:25:20+00:00Added an answer on June 14, 2026 at 8:25 am

    You could look at something like this:

    The model

    from django.db import models
    class LoanCalc(models.Model):
        amount_of_vehicle = models.DecimalField()
        tenure = models.DecimalField()
        interest_rate = models.DecimalField()
        equity = models.DecimalField()
        depreciation_rate = models.DecimalField()
    
        def interest(self):
            return((self.interest_rate/100) * self.amount_of_vehicle *(self.tenure/12))
        def management_fee(self):
            return 0.01 * (self.amount_of_vehicle + self.interest())
    

    The view

    # views.py
    from django.core.mail import send_mail
    from django.template.loader import get_template
    from django.template import Context
    
    from .models import LoanCalc
    
    def loan_calc(request, **kwargs):
        calc = LoanCalc.objects.create(**kwargs)
    
        # Render your calc model in a template and use send_mail to email it
        send_mail(
            'This is your loan calculation!',
            get_template('carloan/email.txt').render(
                Context({
                    'calc': calc,
                })
            ),
            'you@example.com',
            ['receiver@gexample.com']
        )
    
        return render_to_response('carloan/result.html',
                                  {'form': forms, 'calc': calc}
                                  context_instance=RequestContext(request))
    

    The view template

    # result.html
    <table>
        <tr>
           <td>Interest</td>
           <td>{{ calc.interest }}</td>
        </tr>
        <tr>
           <td>Management fee</td>
           <td>{{ calc.management_fee }}</td>
        </tr>
    </table>
    

    The email template

    # email.txt
    Hi, this is your loan calculation overview:
    
    Interest: {{ calc.interest }}
    Management fee: {{ calc.management_fee }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this model: from django.db import models from django.contrib.auth.admin import User # Create your
I have following model (campaigns/models.py) from django.db import models from django.contrib.auth.models import User class
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
from django.db import models from django.contrib.auth.models import User class Product(models.Model): name = models.CharField(max_length =
My models.py from django.db import models from django.contrib.auth.models import User class Song(models.Model): uploader =
I have the following model: from django.db import models from django.contrib.auth.models import User class
I have the following model setup. from django.db import models from django.contrib.auth.models import User
Consider the following django model from django.db import models from django.contrib import auth class
I have a form like so: from django import forms from django.contrib.auth.models import User
from django.contrib.auth.models import User u = User.objects.get(username='test') user.password u'sha1$c6755$66fc32b05c2be8acc9f75eac3d87d3a88f513802 Is reversing this password encryption

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.