我在Django中制作了Crud,但是我看不到数据库中的项目,可以创建合同,但看不到它们进行编辑或删除。我将它与不需要重新加载页面的javascript代码和ajax一起使用
这是我的views.py代码
samples= ['s1', 's2', 's3', 's4']
assemblies = ['s3', 's4']
input_dir="./input/"
results_dir="./results/"
rule all:
input:
expand( results_dir + 'annotation/{sample}.annotated.bam', sample= samples)
rule cp_assemblies:
input:
fa= input_dir + '{sample}.bam'
output:
bam= results_dir + 'assembly/{sample}.bam'
shell:
"""
cp -v -f {input.fa} > {output.bam}
"""
rule assemble:
input:
fq= input_dir + '{sample}.fq.gz'
output:
bam= results_dir + 'assembly/{sample}.bam'
shell:
"""
my_assembler {input.fq} > {output.bam}
"""
rule annotate:
input:
bam= results_dir + 'assembly/{sample}.bam'
output:
bam= results_dir + 'annotation/{sample}.annotated.bam'
shell:
"""
my_annotator {input.bam} > {output.bam}
"""
我的idex.html代码
from django.shortcuts import render
# Django
# Django
from django.contrib.messages.views import SuccessMessageMixin
from django.urls import reverse_lazy
from django.views import generic
# Project
from .forms import ContractForm
from .models import Contract
from bootstrap_modal_forms.mixins import PassRequestMixin, DeleteAjaxMixin
class Index(generic.ListView):
model = Contract
context_object_name = 'contracten'
template_name = 'contract/index.html'
# Create
class ContractCreateView(PassRequestMixin, SuccessMessageMixin, generic.CreateView):
template_name = 'contract/create_contract.html'
form_class = ContractForm
success_message = 'Success: contract aan gemaakt.'
success_url = reverse_lazy('index')
# Update
class ContractUpdateView(PassRequestMixin, SuccessMessageMixin, generic.UpdateView):
model = Contract
template_name = 'contract/delete_contract.html'
form_class = ContractForm
success_message = 'Success: contract upgedated.'
success_url = reverse_lazy('index')
# Read
class ContractReadView(generic.DetailView):
model = Contract
template_name = 'contract/read_contract.html'
# Delete
class ContractDeleteView(DeleteAjaxMixin, generic.DeleteView):
model = Contract
template_name = 'contract/delete_contract.html'
success_message = 'Success: Book was deleted.'
success_url = reverse_lazy('index')
def contract(request):
return render(request, 'contract/index.html'),
models.py
{% extends 'base.html' %}
{% block content %}
{% include "_modal.html" %}
<div class="container mt-3">
<div class="row">
<div class="col">
<div class="row">
<div class="col-12 mb-3">
<button class="create-Contract btn btn-primary" type="button" name="button">
<span class="fa fa-plus mr-2"></span>maak contract aan</button>
</div>
<div class="col-12 mb-3">
{% if contracten %}
<table class="table">
<thead>
<tr>
<th class="text-center" scope="col">#</th>
<th class="text-center" scope="col">organisatie</th>
<th class="text-center" scope="col">tussenpersoon</th>
<th class="text-center" scope="col">tussenpersoon_email</th>
<th class="text-center" scope="col">lezen / Updaten / verwijderen</th>
</tr>
</thead>
<tbody>
{% for contract in contracten %}
<tr>
<th class="text-center" scope="row">{{ contract.id }}</th>
<td class="text-center">{{ contract.organisatie }}</td>
<td class="text-center">{{ contract.tussenpersoon }}</td>
<td class="text-center">{{ contract.tussenpersoon_email }}</td>
<td class="text-center">
<button type="button" class="read-Contract btn btn-sm btn-primary" data-id="{% url 'read_Contract' contract.id %}">
<span class="fa fa-eye"></span>
</button>
<button type="button" class="update-Contract btn btn-sm btn-primary" data-id="{% url 'update_Contract' contract.id %}">
<span class="fa fa-pencil"></span>
</button>
<button type="button" class="delete-Contract btn btn-sm btn-danger" data-id="{% url 'delete_Contract' contract.id %}">
<span class="fa fa-trash"></span>
</button>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-primary">u heeft nog geen contracten</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block extrascripts %}
<script type="text/javascript">
$(function () {
// Create book button
$(".create-Contract").modalForm({formURL: "{% url 'create_Contract' %}"});
// Update book buttons
$(".update-Contract").each(function () {
$(this).modalForm({formURL: $(this).data('id')});
});
// Read book buttons
$(".read-Contract").each(function () {
$(this).modalForm({formURL: $(this).data('id')});
});
// Delete book buttons
$(".delete-Contract").each(function () {
$(this).modalForm({formURL: $(this).data('id')});
});
});
</script>
{% endblock extrascripts %}
forms.py
from django.db import models
class Contract(models.Model):
id = models.AutoField(primary_key=True, null=False, blank=False)
organisatie = models.CharField(max_length=145, null=False, blank=False)
tussenpersoon = models.CharField(max_length=145, null=True, blank=True)
tussenpersoon_email = models.EmailField(null=True, blank=True)
我希望有人可以帮助我完成我的代码