Я нахожусь в процессе написания формы класса UpdateView, я использую inlineformset_factory для получения объектов ForignKey и его работ, моя проблема в том, что я хотел бы перебрать все ForignKey с HTML для отображения всех его объектов, и я не Я действительно не знаю, как этого добиться, так как все объекты, на которые я ссылаюсь, формируются. как объявлено в моем forms.py, поэтому мой вопрос: кто-то может помочь мне с данным представлением и формой, как, в HTML если я буду повторять мои объекты ForignKey
Пожалуйста, совет
Спасибо
мой код показан ниже my views.py Обновление вида
class TaskIdUpdateView(UpdateView):
taskidformset = inlineformset_factory(MainTask,ChildTask, fields=('task_description','task_info','task_complete',
'sub_task','task_precent_complete','task_due_date','task_assign'))
model = MainTask
template_name = "taskid_update.html"
form_class = TaskUpdateForm
form.py форма класса
class TaskUpdateForm(ModelForm):
TASK_STATUS_CHOICES = [
('ST', 'STARTED'),
('NS', 'NOT STARTED'),
('IP', 'IN PROGRESS'),
('PA', 'PAUSED'),
('CO', 'COMPLETED'),
]
INPUTֹTIMEֹFORMATS = ['%Y-%m-%d', # '2006-10-25'
'%m/%d/%Y',
'%Y/%m/%d', # '10/25/2006'
'%Y/%m/%d %H:%M',
'%m/%d/%y',
'%Y-%m-%d %H:%M:%S'] # '10/25/06'
#Main Task objects
task_title = forms.CharField(required=False, widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Task Title'}))
global_task_info = forms.CharField(required=True, widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Task Description'}))
due_date = forms.DateTimeField(required=False, input_formats=INPUTֹTIMEֹFORMATS, widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'id': 'picker'
}))
global_task_assign = forms.ModelChoiceField(queryset= UserProfile.objects.all(), widget=forms.Select(attrs={'class':'form-control'} ))
task_status = forms.ChoiceField(label='', choices=TASK_STATUS_CHOICES, widget=forms.Select(attrs={'class':'form-control'}))
complete = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'type':'checkbox', 'class':'custom-control-input', 'id':'switchcomplete'}))
overall_precent_complete = forms.IntegerField(widget=(forms.NumberInput(attrs={'type':'range', 'min':'0', 'max':'100', 'value':'50', 'class':'range-slider__range', 'id':'PreRange'})))
task_location = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}))
#Child Tasks objects
task_description = forms.CharField(max_length=200, widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
task_info = forms.CharField(max_length=500, widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
task_complete = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'type':'checkbox', 'class':'custom-control-input', 'id':'switchcomplete'}))
sub_task = forms.CharField(max_length=500, widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
task_precent_complete = forms.IntegerField(widget=(forms.NumberInput(attrs={'type':'range', 'min':'1', 'max':'100', 'value':'50', 'class':'slider', 'id':'myRange'})))
task_due_date = forms.DateTimeField(input_formats=INPUTֹTIMEֹFORMATS, widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'id': 'picker'
}))
task_assign = forms.ModelChoiceField(queryset= UserProfile.objects.all(), widget=forms.Select(attrs={'class':'form-control'} ))
class Meta:
model = MainTask
fields = ['task_title',
'global_task_info',
'due_date',
'global_task_assign',
'task_status',
'complete',
'overall_precent_complete',
'task_location',
'global_task_assign',
'task_status',]
taskidformset = inlineformset_factory(MainTask,ChildTask, fields=('task_description','task_info','task_complete',
'sub_task','task_precent_complete','task_due_date','task_assign'))
обновление. html
{% extends 'base.html'%}
{% load static from static %}
{% block content %}
<!--accordion css-->
<link href="{% static 'css/range.css' %}" rel="stylesheet">
<div class="conatainer">
<div class="col text-center py-5">
<form action="" class="" method="POST">
<h3 class="mt-3 text-left">Update Task </h3>
<hr>
<p class="text-muted text-left">Update Itom task</p>
{% csrf_token %}
{% if form.errors %}
</form>
<!-- Error messaging -->
<div id="errors">
<div class="inner">
<p>There were some errors in the information you entered. Please correct the following:</p>
<ul>
{% for field in form %}
{% if field.errors %}<li>{{ field.label }}: {{ field.errors|striptags }}</li>{% endif %}
{% endfor %}
</ul>
</div>
</div>
<!-- /Error messaging -->
{% endif %}
<div class="input-group mt-3 mb-3 mr-auto">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="fas fa-book-medical"></i></span>
</div>
{{ form.task_title}}
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-pen"></i></span>
</div>
{{form.global_task_info}}
</div>
<!---date time picker-->
<h6 class="text-left">Task Due Date</h6>
<div class="input-group date mb-3 col-3">
<div class="input-group-append">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
{{ form.due_date }}
</div>
<!--end of date time picker-->
<!---Task Location-->
<div class="input-group mb-3 mt-3 col-8">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-map-marked-alt"></i></div>
{{form.task_location}}
</div>
</div>
<!--End Of Task Location-->
<!---user assign-->
<h6 class="text-left">Assign Task to IT member</h6>
<div class="input-group mb-3 mt-3 col-8">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user-tie"></i></div>
{{form.global_task_assign}}
</div>
</div>
<!--End Of User Assign-->
<h6 class="text-left">Set Task Status</h6>
<div class="input-group mb-3 mt-3 col-4">
<div class="input-group-prepend">
<div class="input-group-text"><i class="far fa-caret-square-right"></i></div>
</div>
{{form.task_status}}
</div>
<div class="range-slider mb-4">
<h6 class="text-left">Set Task Global Progress</h6>
{{form.overall_precent_complete}}
<span class="range-slider__value">0</span>
</div>
<h4 class="mt-3 text-left">SubTask Section </h4>
<hr>
<!---subtask section-->
<div id="accordion">
{{formset.task_description }}
<div class="card">
<div class="card-header text-left bg-secondary">
<a class="card-link" data-toggle="collapse" href="#collapseOne">
Collapsible Group Item #1
</a>
</div>
<div id="collapseOne" class="collapse show" data-parent="#accordion">
<div class="card-body">
</div>
</div>
</div>
</div>
<!---End subtask section-->
<div class="col text-left">
<button type="submit" value="Save" class="btn btn-primary btn-lg text-white mt-2"><span><i class="fas fa-database"></i></span> Create Task</button>
</div>
</div>
</div>
{% endblock content %}