django - Customize select widget in a foreignkey field -


i have following models:

class regioncategory(models.model):     """categories of regions"""      symbol = models.charfield(max_length=15)     description = models.charfield(max_length=50)  class region(models.model):     """region model"""      region = models.charfield(max_length=30)     category = models.foreignkey(regioncategory)  class md_orderlog(models.model):     """order log model"""      order_region = models.foreignkey(region) 

nothing uncommon, model foreign key model.

i have modelform also:

class md_orderlogform(forms.modelform):     """model form of md_orderlog model"""      def __init__(self, *args, **kwargs):         super(md_orderlogform, self).__init__(*args, **kwargs)          self.fields['order_region'] = forms.modelchoicefield(               label=("project region"), widget=forms.select,                  queryset=region.objects.all()) 

what want , don't know how customize order_region field in form select show region items divided category, this:

category1     region1     region2     region3  category2     region4     region5     region6 

any ideas?, thanks!


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -