Hello Moogly,

$ wine/models.py:


class ColorBase(models.Model):     
        class Meta:                                                         
                                                                    
abstract = true
        
        COLORS_CHOICHES = (
                        ("Red",    "Red"), 
                        ("Blue",   "Blue"), 
                 )                                                          
                                                                            
                                   
        tone= models.CharField(max_length = 32, choices = COLORS_CHOICHES) 
                                                                            
                                                              
class RedColor(ColorBase):                                                  
                                                                    
COLORS_CHOICHES = (                                                         
                                                             ("Light red", 
   "light red"),                                                           
                                           ("Dark red",     "dark red")     
                                                                            
                )                                                          
                                                                        
....                                                                       
   
               
 
class WhiteColor(ColorBase):                                                
                                                                    
COLORS_CHOICHES = (                                                         
                                                           ("Light white",  
"light 
white"),                                                                   
                                 ("Dark white",   "dark white")             
                                                                            
        )                                                                  
                                                                 ....       
                                                                   

Now in your $ wine/admin.py:

class ColorBaseAdmin(admin.ModelAdmin):
     model = ColorBase
      def formfield_for_dbfield(self, db_field, **kwargs):

        if db_field.name == 'status':

            kwargs.update(

                {'choices':self.model. COLORS_CHOICHES}

            )
            #I THINK THIS IS NOT REQUIRED BECAUSE AUTOMATICALLY YOU HAVE 
MODEL UPDATED.. you can omit these two lines

            if settings.DEBUG self.model == ColorBase:

                logger.warning("Please set the model in your model admin to 
display correct status' choices")

        return super(ColorBaseAdmin, self).formfield_for_dbfield(

            db_field, **kwargs)

class RedColorAdmin(ColorBaseAdmin):
    model=RedColor
class WhiteColorAdmin(ColorBaseAdmin):
    model=WhiteColor

admin.site.register(RedColor, RedColorAdmin)
admin.site.register(WhiteColor, WhiteColorAdmin)

If you need choices in your frontend form you have to pass 
YourColor.COLOR_CHOICES choices to your form field in your form's __init__ 
function
#HOPE THIS WORKS BUT I DIDN'T TEST IT

class BaseColorForm(forms.ModelForm):
    
    def __init__(self, **kwargs):
        self.base_fields['tone'].choices=self.Meta.model.COLOR_CHOICES

        super(BaseColorForm, self).__init__(*args, **kwargs)

class RedColorForm(BaseColorForm):
    class Meta:
        model = RedColor

class WhiteColorForm(BaseColorForm):
    class Meta:
        model = WhiteColor





Hope this helps

-- 
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+unsubscr...@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/c7a5f665-6ffa-42ba-be12-39868ce726c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to