Questions tagged [django-modeladmin]

132 questions
2
votes
1 answer

How can I get custom form field value from within Django Admin's response_change?

I've added a custom functionality to a model by overriding change_form.html. Basically, I'm letting users change the objects of a model if these changes were approved by the admin. I added two buttons, named accept-suggestion and decline-suggestion…
2
votes
1 answer

Django ModelAdmin admin_order_field with nulls_last

I am trying to sort column of ModelAdmin list field with admin_order_field with nulls_last such as: class UserProfileAdmin(admin.ModelAdmin): def get_sum_amount(self, obj): return obj.sum_amount get_sum_amount.admin_order_field =…
Petr Dlouhý
  • 857
  • 9
  • 11
2
votes
1 answer

How to access Django Model Fields from save_formset

I have an Inline Model in Django model admin , and I need to create a condition before saving the items, here is the code am using : class PRCItemInline(admin.TabularInline): def get_form(self, request, obj=None, **kwargs): form =…
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116
2
votes
2 answers

How to fix djangos's decotators Error: Wrapped class must subclass ModelAdmin

I have been whriten API for my app. End when I to start servver terminal cought this: File "/home/user/MyProjects/forest-venv/forest/logginsite/admin.py", line 11, in class LScharacteristicAdmin(DynamicRawIDMixin): File…
2
votes
1 answer

Wagtail ModelAdmin with list_filter error: FieldDoesNotExist: Region has no field named 'p'

I've got a model I'm exposing through Wagtail's modeladmin that works until I try to apply a list_filter including a ForeignKey. I've got a self-referencing model (to store Counties, Cities, and Towns) called Region that I'd like to be able to…
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
2
votes
1 answer

Django adding multiple records with the same foreign key in ModelAdmin

Suppose I have the following two models task and person. Now each person can have multiple tasks (one to many relationship). Now in the admin app for a person I can only add one foreign key per record thus I'll have to create multiple records for a…
James Franco
  • 4,516
  • 10
  • 38
  • 80
2
votes
1 answer

Django Admin Page: Help Text for Model Methods?

I have a model method in Django that I am displaying on an admin page just like I would a model field. With a field, I can just add a help_text argument to it to give a description of what the field is and what the user should put into it. …
kloddant
  • 1,026
  • 12
  • 19
2
votes
2 answers

How to test ModelForm save() method saves changes in model?

I have overridden AdminModel's ModelForm to make User fields edible and savable from Person's admin change form. class Person(models.Model): user = models.OneToOneField(User) #and also some char, text fields @property def…
2
votes
1 answer

What is the use of the third type in the ModelAdmin.list_filter documentation? [django]

The ModelAdmin documentation for Django 1.6 has something that confuses me. On https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter, the third type doesn't make sense to me. The documentation says…
1
vote
1 answer

Django relation of models

I have an e-commerce project and I stuck at admin view. I have 2 models, namely Order and OrderItem. They are connected with FK relationship, and when Order is created I create both Order and related OrderItems in my admin page. Orders in admin…
1
vote
0 answers

Hide one of the User.ModelAdmin.fieldsets if User role changes in django

Hi I want to hide some fieldsets in admin if user role changes. In get_queryset() I'm changing queryset if role == 'CMS' I also want to hide Permission fieldset for same role. Here is my admin: Note: I'm Using list for fieldsets here I pasted…
Rajat Jog
  • 197
  • 1
  • 10
1
vote
1 answer

How to resolve this "Invalid default value for a django.models field error"?

I am creating a student model which records homework details of a student. It works in a way that student has been given work to do at home with some deadlines of days or hours. When I migrate, I get this error I am getting this error File…
1
vote
3 answers

Django Admin Panel: Show/Hide Fields If Specific Value Is Selected In A Dropdown

What am I doing wrong? In django admin-panel I want to show/hide field(s) based on the choice dropdown. Also the, choice dropdown lies on parent foreign-key related model and the fields that are to be shown/hidden lies in child model or as an…
kiliman13
  • 91
  • 2
  • 4
1
vote
2 answers

Show created and edited fields in Django admin form

I have this model class Volunteer(models.Model): STATUSES = ( ('Active', 'Active'), ('Paused', 'Paused'), ('Inactive', 'Inactive'), ) first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) email_address…
user14411637
1
vote
0 answers

Djano Admin Forms queryset for ManyToMany Fields

How does one add request.user in init and save methods I want to use owner = request.user. At the moment I have hardcoded in init as owner=2 class QuizAdminForm(forms.ModelForm): class Meta: model = Quiz exclude = [] …
1 2
3
8 9