Thursday, May 2, 2019

How to create dependent drop down list

fb.jpg

#My form script is
from django import forms
from django.db import models
import os,string
# My production Drive
class my_drive_module(forms.Form):
drives_a = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')]

#floder
list_with_tuples = [(x, x) for x in drives_a]
EMPTY_CHOICES = [('', 'All')] + list_with_tuples

# Folder List
#only for ref D:\0pramod\Project
os.chdir(r"D:\0pramod\Project")
my_folder = os.getcwd()
list_entries = os.listdir(my_folder)
list_with_folder = [(x, x) for x in list_entries]
EMPTY_CHOICES_FOLDER = [('', 'All')] + list_with_folder

#Approve tag CharField
Production_Drive = forms.CharField(widget=forms.RadioSelect(choices=list_with_tuples))
pro_folder= forms.CharField(label='Drive folder', widget=forms.Select(choices=EMPTY_CHOICES),required=True)

#My View script is


from django.shortcuts import render
from django.views.generic import TemplateView
from django.http import HttpResponse
from.forms import my_drive_module
from django.contrib import messages
import os
def my_drive_fun(request):

if request.method =='POST':
form=my_drive_module(request.POST or None)
if form.is_valid():
Production_Drive = form.cleaned_data['Production_Drive']
work_drive = form.cleaned_data['work_drive']

#messages.warning(request, 'Please correct the error below.')
#print(Production_Drive,work_drive,show_name,show_sup,show_coor,pro_folder,work_folder)
form=my_drive_module()
drive_data={'form':form}
return render(request,'my_drive.html',locals())

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1ff2a82c-007e-4b87-8bb5-36b8376e52b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment