Skip to content

Instantly share code, notes, and snippets.

@guilhermecarvalhocarneiro
Created February 19, 2014 17:35
Show Gist options
  • Save guilhermecarvalhocarneiro/9097083 to your computer and use it in GitHub Desktop.
Save guilhermecarvalhocarneiro/9097083 to your computer and use it in GitHub Desktop.
Redirecionar conforme limite do usuário
def get_form(self, request, obj=None, **kwargs):
form = super(EstabelecimentoAdmin, self).get_form(request, obj, **kwargs)
import pdb
pdb.set_trace()
try:
if not request.user.is_superuser:
if Usuario(user=request.user).get_limit() >= self.model.objects.filter(user=request.user).count() and obj == None:
return render_to_response('limit_places.html', {'app_label': 'Limite atingido'})
form.base_fields['cidade'].queryset = Usuario(user=request.user).get_city()
except Exception, e:
print e
finally:
return form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment