-
-
Save joaodubas/848394 to your computer and use it in GitHub Desktop.
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 models import Pais | |
class MyForm(forms.Form): | |
pais = forms.ModelChoiceField(queryset = Pais.objects.all()) | |
def __init__(self, *args, **kwargs): | |
continente = kwargs.pop('continente', None) | |
super(MyForm, self).__init__(*args, **kwargs) | |
if continente: | |
self.fields['pais'].queryset = self.fields['pais'].queryset.filter(continente=continente) |
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 forms import MyForm | |
def my_view(request): | |
... | |
form = MyForm(continente='americano') | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment