Skip to content
Advertisement

Tag: django-admin

Catch IntegrityError in Django Admin

Working with Django 1.4 I would like to catch an Integrity Error when a user does enter a duplicate value. At this moment the application just shows the default Django error page. (debug = True) model admin form At this moment I get an error page showing a ValidationError instead of an IntegrityError. (Which makes perfect sense) How would I

Django admin is_staff based on group

Is it possible to have is_staff selected by choosing a group? Let’s say there are two groups: users, admins When a new user is in the users group he is not staff, but if he is in the admins group he is staff. Answer I managed to make it work by extending the UserAdmin class and in the get_form function

Change Python Class attribute dynamically

I have a Class B inheriting Class A with a class attribute cls_attr. And I would like to set dynamically cls_attr in class B. Something like that: I tried several things. I know i might not be looking in the right place but i am out of solutions. EDIT: Classes are django admin classes Thanks. Answer class attributes can be

How to limit choices of ForeignKey choices for Django raw_id_field

How do you limit what choices are shown for ForeignKey fields in Django’s admin when they’re displayed using the raw_id_fields option? When rendered as a select box, it’s simple to define a custom ModelForm to set that field’s queryset value with the choices to want. However, this queryset appears to be completely ignored when rendered using raw_id_fields. It generates a

Nothing happens when I do: python manage.py command

I’m new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn’t output anything. Wondering what I’m doing wrong. Answer First, check if python is fully installed by typing “python” in a shell. Then you should try

How to use can_add_related in Django Admin

I’ve read about the can_add_related feature here: https://code.djangoproject.com/ticket/9071 I tried using it this way: But this throws a TypeError and I don’t know how to solve this. Can someone point me in the right direction? Thank you. Answer This is probably coming in late. But for other viewers reference,

Paginator for inline models in django admin

I have this simple django model consisting of an sensor and values for the specific sensor. The number of values per Pyranometer is high (>30k). Is it somehow possible to paginate PyranometerValues by a specific day or generell apply a paginator to the admin inline view? Answer Have you checked raw_id_fields attribute? I think you might find it useful.

Advertisement