Sunday, February 2, 2020

How to iterate over inlineformset_factory fields only?

Hello,

I am trying to figure out how to access inlineformset_factory ,i set to represent my ForeignKey fields to present them in html i would like to iterate over those inlineformset_factory only in html, but i can't figure out how to achieve it, i can get display only field manually like {{form.task_description}} , but no luck to iterate over all ForeignKey fields , i would like to dispaly each object in collapse bs4
if someone could help me point to achieve it.

Please advice

Thanks


my view.py related class goes as follows

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


my formd.py related class

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=Falsewidget=forms.TextInput(attrs={'class':'form-control','placeholder':'Task Title'}))
    global_task_info = forms.CharField(required=Truewidget=forms.Textarea(attrs={'class':'form-control','placeholder':'Task Description'}))
    due_date = forms.DateTimeField(required=Falseinput_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=Falsewidget=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=200widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
    task_info = forms.CharField(max_length=500widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
    task_complete = forms.BooleanField( required=Falsewidget=forms.CheckboxInput(attrs={'type':'checkbox''class':'custom-control-input''id':'switchcomplete'}))
    sub_task = forms.CharField(max_length=500widget=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'))
            


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/89d1f875-07f0-41ae-bc6e-6b81689a89e5%40googlegroups.com.

No comments:

Post a Comment