Menu
  • HOME
  • TAGS

Django-admin list_editable enable/disable on the fly (edit/view mode check)

django,django-admin,django-modeladmin

As for me it's better to override changelist_view method of admin.ModelAdmin: class EntityModelAdmin(admin.ModelAdmin): list_display = ('name', 'barcode', 'short_code', ) list_editable = ('barcode', 'short_code', ) @csrf_protect_m def changelist_view(self, request, extra_context=None): """ The 'change list' admin view for this model. Overrided only for add support of edit/view mode switcher. """ ...parent code......

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

python,django,django-forms,django-testing,django-modeladmin

def test_form_saves_values_to_instance_user_on_save(self): """ test form saves name, surname, email values to corresponding User object when commiting form """ person = Person.objects.get(user__username='admin') personform = PersonForm(instance=person, data={'name': 'has_changed'}) if personform.is_valid(): person = personform.save() self.assertEquals(person.user.first_name, "has_changed") else: self.fail("personform not valid") I think you also need to exclude the user field from your form...

Django: conditional ModelAdmin depending on object

django,django-admin,django-modeladmin

Django-Polymorphic definitely seems the way to go. It's easy to use and automatically gives me the correct modelAdmin when I click through a base object, something I couldn't replicate with Proxies. Only problem is a table is created for each child class, even if the child class doesn't have any...

How can I override the “media” property of Django's ModelAdmin and make it dynamic?

javascript,django,django-admin,django-modeladmin

Shortly after writing up the above question, I found a technique that works. Instead of defining a Media class, I just manually add ALL of my css/js via the media method: from django.contrib import admin class MyModelAdmin(admin.ModelAdmin): model = MyModel ... @property def media(self): media = super(MyModelAdmin, self).media css =...