many-to-many in list display django

You may not be able to do it directly. From the documentation of list_display ManyToManyField fields aren’t supported, because that would entail executing a separate SQL statement for each row in the table. If you want to do this nonetheless, give your model a custom method, and add that method’s name to list_display. (See below … Read more

Resize fields in Django Admin

You should use ModelAdmin.formfield_overrides. It is quite easy – in admin.py, define: from django.forms import TextInput, Textarea from django.db import models class YourModelAdmin(admin.ModelAdmin): formfield_overrides = { models.CharField: {‘widget’: TextInput(attrs={‘size’:’20’})}, models.TextField: {‘widget’: Textarea(attrs={‘rows’:4, ‘cols’:40})}, } admin.site.register(YourModel, YourModelAdmin)

Django admin: how to sort by one of the custom list_display fields that has no database field

I loved Greg’s solution to this problem, but I’d like to point that you can do the same thing directly in the admin: from django.db import models class CustomerAdmin(admin.ModelAdmin): list_display = (‘number_of_orders’,) def get_queryset(self, request): # def queryset(self, request): # For Django <1.6 qs = super(CustomerAdmin, self).get_queryset(request) # qs = super(CustomerAdmin, self).queryset(request) # For Django … Read more

Add custom form fields that are not part of the model (Django)

Either in your admin.py or in a separate forms.py you can add a ModelForm class and then declare your extra fields inside that as you normally would. I’ve also given an example of how you might use these values in form.save(): from django import forms from yourapp.models import YourModel class YourModelForm(forms.ModelForm): extra_field = forms.CharField() def … Read more

Troubleshooting “Related Field has invalid lookup: icontains”

Have you tried adding the __fieldname on those Lingua references in the ListinoTraduttoreAdmin search_fields, like: class ListinoTraduttoreAdmin(admin.ModelAdmin): list_display = (“traduttore”, “linguaDa”, “linguaA”, “prezzoParola”, “prezzoRiga”, “scontoCat”, “scontoFuzzy”, “scontoRipetizioni”) search_fields = [‘traduttore__nome”, “linguaDa__field1”, “linguaA_field2”]

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)