Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. class LocModelForm(forms.ModelForm):
  2. def __init__(self,*args,**kwargs):
  3. super(LocModelForm,self).__init__(*args,**kwargs)
  4. self.fields['icons'] = forms.ModelChoiceField(queryset = Photo.objects.filter(galleries__title_slug = "markers"))
  5. self.fields['icons'].widget.attrs['class'] = 'mydds'
  6.  
  7.  
  8. class Meta:
  9. model = Loc
  10. widgets = {
  11. 'icons' : forms.Select(attrs={'id':'mydds'}),
  12. }
  13.  
  14. class Media:
  15. css = {
  16. "all":("/media/css/dd.css",)
  17. }
  18. js=(
  19. '/media/js/dd.js',
  20. )
  21.  
  22. class LocAdmin(admin.ModelAdmin):
  23. form = LocModelForm
  24.  
  25. class MySelect(forms.Select):
  26. def render_option(self, selected_choices, option_value, option_label):
  27. # look at the original for something to start with
  28. return u'<option whatever>...</option>'
  29.  
  30. class LocModelForm(forms.ModelForm):
  31. icons = forms.ModelChoiceField(
  32. queryset = Photo.objects.filter(galleries__title_slug = "markers"),
  33. widget = MySelect(attrs = {'id': 'mydds'})
  34. )
  35.  
  36. class Meta:
  37. # ...
  38. # note that if you override the entire field, you don't have to override
  39. # the widget here
  40. class Media:
  41. # ...
Add Comment
Please, Sign In to add comment