Last active
September 4, 2018 18:26
-
-
Save fhdez/130441cd2e978280f03fa4bf56340f27 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
class AsignaturaNMEAdmin(admin.ModelAdmin): | |
model = AsignaturaNME | |
list_display = get_fieldnames(model) | |
exclude = ['slug'] | |
search_fields = ['nombre', 'CampoFormativoNME', 'grado'] | |
class CustomModelChoiceField(forms.ModelChoiceField): | |
def label_from_instance(self, obj): | |
return "%s - %s - %s" % (obj.nombre, obj.ciclo.nivel, obj.ciclo) | |
def formfield_for_foreignkey(self, db_field, request, **kwargs): | |
if db_field.name == 'grado': | |
return self.CustomModelChoiceField( | |
queryset=Grado.objects.validados().order_by( | |
'ciclo__nivel', | |
'ciclo', | |
'nombre' | |
).exclude(ciclo__nivel=4) | |
) | |
return super(AsignaturaNMEAdmin, self).formfield_for_foreignkey( | |
db_field, | |
request, | |
**kwargs | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment