Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SelectWOA(Select):
- def create_option(self, name, value, label, selected, index,
- subindex=None, attrs=None):
- option_dict = super(SelectWOA, self).create_option(name, value,
- label, selected, index, subindex=subindex, attrs=attrs)
- #Category.objects.
- try:
- option_dict['attrs']['style'] = 'color: ' + Category.objects.get(name=label).color + ';'
- except:
- pass
- return option_dict
- from django.forms import ChoiceField, ModelChoiceField
- from category.models import Category
- class ProductAdminForm(ModelForm):
- test_field = ModelChoiceField(queryset=Category.objects.all(), widget=SelectWOA())
- class Meta:
- model = Product
- exclude = ['category']
- fields = ('name', 'image', 'image2', 'category', 'test_field',)
- from django.db import models
- class ProductCastumAdmin(admin.ModelAdmin):
- #fields = ('name',)
- form = ProductAdminForm
Add Comment
Please, Sign In to add comment