Hi,

I'd like to make a mixin to set the placeholder text in the widget attrs.

Reading this https://code.djangoproject.com/ticket/5793, it seems that 
extending Meta for custom fields is somewhat discouraged.

Would the following be the recommended way to do it?  Just adding a class 
variable to the Form class?

class PlaceHolderMixin(object):                                             
    
                                                                            
    
    placeholders = {}                                                       
    
                                                                            
    
    def __init__(self, *args, **kwargs):                                   
     
        super(PlaceHolderMixin, self).__init__(*args, **kwargs)             
    
        for field_name, field in self.fields.items():                       
    
            if field_name not in self.placeholders:                         
    
                continue                                                   
     
            self.fields[field_name].widget.attrs['placeholder'] = 
self.placeholders[field_name]


class MyForm(PlaceHolderMixin, ModelForm):                               
                                                                            
    
    placeholders = {                                                       
     
        'name': 'blah blah',                    
        'owner': 'blah blah',
    }                                                                       
    
                                                                            
    
    class Meta:                                                             
    
        model = MyModel
 

-- 
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/423a8164-47bb-498c-b651-48ea1a3f7464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to