Created
December 17, 2015 13:07
-
-
Save RodolfoSilva/8ec913cecf95cca53613 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 django.contrib import admin | |
from .models import Categoria | |
class CategoriaForm(forms.ModelForm): | |
class Meta: | |
model = Categoria | |
fields = '__all__' | |
def __init__(self, *args, **kwargs): | |
super(CategoriaForm, self).__init__(*args, **kwargs) | |
self.fields['parent'].choices = categoria_pai_as_choices() | |
def categoria_pai_as_choices(): | |
categorias = [] | |
categorias.append(['', '-----------']) | |
for categoria in Categoria.objects.filter(parent=None).all(): | |
categorias.append([categoria.id, categoria.nome]) | |
return categorias |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment