Created
June 26, 2013 17:35
-
-
Save joshkehn/5869518 to your computer and use it in GitHub Desktop.
Ingredient ModelForm (Django)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from menu.models import Ingredient, Diet, FoodPreference | |
class IngredientForm (forms.ModelForm): | |
class Meta: | |
model = Ingredient | |
exclude = ["franchise"] | |
def __init__ (self, *args, **kwargs): | |
brand = kwargs.pop("brand") | |
super(IngredientForm, self).__init__(*args, **kwargs) | |
self.fields["diets"].widget = forms.widgets.CheckboxSelectMultiple() | |
self.fields["diets"].help_text = "" | |
self.fields["diets"].queryset = Diet.objects.all() | |
self.fields["preferences"].widget = forms.widgets.CheckboxSelectMultiple() | |
self.fields["preferences"].help_text = "" | |
self.fields["preferences"].queryset = FoodPreference.objects.filter(franchise=brand) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment