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
Tag: django-admin
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
Django 1.7: how to make ManyToManyField required?
I have a Django Model with ManyToManyField in it. I need to require user to select at least one M2M value in this field. I tried to set blank=False to M2M field but it didn’t help. I can solve this situation with custom Form definition or with override save() method for Person model. Is it possible to prevent create Person
unregister or register models conditionally in django admin
Is it possible to conditionally register or unregister models in django admin? I want some models to appear in django admin, only if request satisfies some conditions. In my specific case I only need to check if the logged in user belongs to a particular group, and not show the model if the user (even if superuser) is not in
ImproperlyConfigured: There are duplicate field(s) in PackageAdmin.fieldsets
I have a very simple model : here is the admin.py : This implementation give me the following error : Any idea why ? If I let the second ‘fields’ empty, I don’t get the error. But if I let the first ‘fields’ empty, I still have this error. Answer Björn Kristinsson did solve my issue (see in the comment
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.