Django Passing data between views

There are different ways to pass data between views. Actually this is not much different that the problem of passing data between 2 different scripts & of course some concepts of inter-process communication come in as well. Some things that come to mind are – GET request – First request hits view1->send data to browser … Read more

Override a form in Django admin

You can override forms for django’s built-in admin by setting form attribute of ModelAdmin to your own form class. See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin It’s also possible to override form template – have a look at https://docs.djangoproject.com/en/dev/ref/contrib/admin/#custom-template-options If you’re looking specifically for autocomplete I can recommend https://github.com/crucialfelix/django-ajax-selects

How does the order of mixins affect the derived class?

The MRO is basically depth-first, left-to-right. See Method Resolution Order (MRO) in new style Python classes for some more info. You can look at the __mro__ attribute of the class to check, but FooMixin should be first if you want to do “check A” first. class UltimateBase(object): def dispatch(self, *args, **kwargs): print ‘base dispatch’ class … Read more

Example of Django Class-Based DeleteView

Here’s a simple one: from django.views.generic import DeleteView from django.http import Http404 class MyDeleteView(DeleteView): def get_object(self, queryset=None): “”” Hook to ensure object is owned by request.user. “”” obj = super(MyDeleteView, self).get_object() if not obj.owner == self.request.user: raise Http404 return obj Caveats: The DeleteView won’t delete on GET requests; this is your opportunity to provide a … Read more