Skip to content

Instantly share code, notes, and snippets.

@gtsalles
Created August 20, 2013 18:04
Show Gist options
  • Save gtsalles/6284965 to your computer and use it in GitHub Desktop.
Save gtsalles/6284965 to your computer and use it in GitHub Desktop.
Demonstration of formfield_for_foreignkey method on Django.
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "usuario":
usuario_id = request.GET.get('usuario_id', None)
if usuario_id:
kwargs['initial'] = usuario_id
if db_field.name == "psicologo":
kwargs["queryset"] = User.objects.filter(is_superuser=True)
return super(EntrevistaAdmin, 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