我正在动态进行收费views.py中的addfees函数,我该如何做任何建议?

时间:2019-02-26 06:03:19

标签: python django

我正在尝试在收费views.py中非常动态地执行addfees函数,并且我试图基于“ gr_no”选择值,实际上还有另一个模型名称(gr_register),gr_register具有主键名称“ gr_no”。根据“ gr_no”选择所有费用记录,并将其添加到费用

models.py(gr_register)

class gr_register(models.Model):
    Gender_Choices = (
        ('M', 'Male'),
        ('FM', 'Female'),
    )
    Status_Choices = (
        ('P', 'Present'),
        ('FM', 'Left'),
    )
    gr_no = models.IntegerField(primary_key=True)
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    date_birth = models.DateField(null=True)
    classes_A = models.ForeignKey(Classes, on_delete=models.CASCADE, related_name="classes_A", default=1, verbose_name="Class of Admission")
    sections_A = models.ForeignKey(Sections, on_delete=models.CASCADE, related_name="sections_A", default=1, verbose_name="Section of Admission")
    gender = models.CharField(max_length=10, choices=Gender_Choices)
    classes_C = models.ForeignKey(Classes, on_delete=models.CASCADE, related_name="classes_C", verbose_name="Current Class")
    sections_C = models.ForeignKey(Sections, on_delete=models.CASCADE, related_name="sections_C", verbose_name="Current Section")
    address = models.CharField(max_length=100, null=True, verbose_name="Home Address")
    area_code = models.ForeignKey(Area, on_delete=models.CASCADE, verbose_name="Area")
    status = models.CharField(max_length=10, choices=Status_Choices, default='P')

    class Meta:
        ordering = ('-gr_no',)

    def __str__(self):
        return self.first_name

models.py(费用)

class fee(models.Model):
    BOOL_CHOICES = ((True, 'Yes'), (False, 'No'))

    Gr_num = models.ForeignKey(gr_register, on_delete=models.CASCADE, default=231)
    fee_code = models.ForeignKey(fees_type, on_delete=models.CASCADE, default=1)
    fee_dues = models. BigIntegerField(default=1000)
    paid_source = models.ForeignKey(fees_source, on_delete=models.CASCADE, default=1)
    class_name = models.ForeignKey(Classes, on_delete=models.CASCADE, default=1)
    paid = models.BooleanField(choices=BOOL_CHOICES, default=1)
    guradian_code = models.ForeignKey(gardian , on_delete=models.CASCADE, default=1)
    due_date = models.DateField(default=timezone.now)
    paid_date = models.DateField(default=timezone.now)

    def __str__(self):
        return str(self.paid)

views.py(费用)

def addfees(request):
    form = feeForm(request.POST or None)
    if request.method == "POST":
        if form.is_valid():
            form.save()
            return redirect('home')
    return render(request, 'fees/addfees.html', {'form': form})

addfees.html

{% extends 'authenticate/base.html' %}
{% block content %}
 <div class="container">
    <h4 class="text-center">ADD Fees</h4>
    <hr/> 
    <form method="POST" action="#" enctype="multipart/form-data">
        {% csrf_token %}
        {% for field in form %}
        <div class="form-group row">
            <label for="id_{{ field.name }}" class="col-2 col-form-label">{{ field.label }}</label>
            <div class="col-10">
                {{ field }}
                {{ field.errors }}
            </div>
        </div>
        {% endfor %}
        <button type="submit" class="btn btn-primary" name="button">Submit</button>
    </form>
 <br/><br/>
</div>  
{% endblock %}

帮助我解决此问题,我不了解该怎么办?我是Django的新手。任何人都不能引导我

0 个答案:

没有答案