FAQ
Django has list_editable. I need to edit is_active flag.

class MyUserAdminForm(ModelForm):
class Meta:
model = User

def clean_is_active(self):
# do something that validates your data
print ' I am here... '
print self.cleaned_data
print self

class MyUserAdmin(admin.ModelAdmin):
.... SOME CODE ....
form = MyUserAdminForm


admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

I put this in admin.py, and I've registered my admin.ModelAdmin code. The
display is fine.

The code above should fail because it doesn't return
self.cleaned_data["is_active"]. But when I reload the development server,
and changed the flag on some users, Django didn't complain, so this piece
of code is not used.

My requirement is to check that the user under change is not a superuser. I
have other things to do within that validation, but you get the idea.

Why is this?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/GkbElmp44loJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Search Discussions

  • Dd at Jul 8, 2012 at 1:44 pm
    Django has list_editable. I need to edit is_active flag.

    class MyUserAdminForm(ModelForm):
    class Meta:
    model = User

    def clean_is_active(self):
    # do something that validates your data
    print ' I am here... '
    print self.cleaned_data
    print self

    class MyUserAdmin(admin.ModelAdmin):
    .... SOME CODE ....
    form = MyUserAdminForm


    admin.site.unregister(User)
    admin.site.register(User, MyUserAdmin)

    I put this in admin.py, and I've registered my admin.ModelAdmin code. The
    display is fine.

    The code above should fail because it doesn't return
    self.cleaned_data["is_active"]. But when I reload the development server,
    and changed the flag on some users, Django didn't complain, so this piece
    of code is not used.

    My requirement is to check that the user under change is not a superuser. I
    have other things to do within that validation, but you get the idea.

    Why is this?

    Thanks.

    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/8nrBEiPwhrEJ.
    To post to this group, send email to django-users@googlegroups.com.
    To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
  • Dd at Jul 8, 2012 at 6:19 pm
    Ah. I think the method is overriding the edit page. In other words, you
    have click on the editpage to see the effect of my fail code. So it doesn't
    trigger if you are on the list view page. Does anyone know what to do with
    the editable submission?
    It should use the same clean_ method, shouldn't it??


    On Sunday, July 8, 2012 9:33:49 AM UTC-4, dd wrote:

    Django has list_editable. I need to edit is_active flag.

    class MyUserAdminForm(ModelForm):
    class Meta:
    model = User

    def clean_is_active(self):
    # do something that validates your data
    print ' I am here... '
    print self.cleaned_data
    print self

    class MyUserAdmin(admin.ModelAdmin):
    .... SOME CODE ....
    form = MyUserAdminForm


    admin.site.unregister(User)
    admin.site.register(User, MyUserAdmin)

    I put this in admin.py, and I've registered my admin.ModelAdmin code. The
    display is fine.

    The code above should fail because it doesn't return
    self.cleaned_data["is_active"]. But when I reload the development server,
    and changed the flag on some users, Django didn't complain, so this piece
    of code is not used.

    My requirement is to check that the user under change is not a superuser.
    I have other things to do within that validation, but you get the idea.

    Why is this?

    Thanks.
    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/R9svhH1WS00J.
    To post to this group, send email to django-users@googlegroups.com.
    To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
  • Tomas Neme at Jul 9, 2012 at 12:38 am

    Ah. I think the method is overriding the edit page. In other words, you have
    click on the editpage to see the effect of my fail code. So it doesn't
    trigger if you are on the list view page. Does anyone know what to do with
    the editable submission?
    It should use the same clean_ method, shouldn't it??
    if you want this validation everywhere you should probably do
    something in the model's .save() method, or even better (to avoid
    monkey patching) register into the pre_save signal

    --
    "The whole of Japan is pure invention. There is no such country, there
    are no such people" --Oscar Wilde
    _|0|_|
    _|_|0|
    0|0|0|
    (\__/)
    (='.'=)This is Bunny. Copy and paste bunny
    (")_(") to help him gain world domination.

    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To post to this group, send email to django-users@googlegroups.com.
    To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedJul 8, '12 at 1:32p
activeJul 9, '12 at 12:38a
posts4
users3
websitedjangoproject.com

People

Translate

site design / logo © 2022 Grokbase