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

Difference between reverse() and reverse_lazy() in Django

Consider these two ways of defining the success_url. The first is commented out, the second is the function: class NewJobCBV(LoginRequiredMixin, CreateView): template_name=”company/job.html” form_class = newJobForm # success_url = reverse_lazy(‘newJob’) def get_success_url(self, **kwargs): return reverse(“newJob”) @CoffeeBasedLifeform : you are right, class attributes are evaluated on import, I checked after reading your answer. So, If we are … Read more

django: Purpose of django.utils.functional.SimpleLazyObject?

The auth middleware adds a user attribute to request that is an instance of SimpleLazyObject. SimpleLazyObject, itself is a subclass of LazyObject. LazyObject is, as described by the actual code: A wrapper for another class that can be used to delay instantiation of the wrapped class SimpleLazyObject merely sets that class (the _wrapped attribute on … Read more

Best way to write an image to a Django HttpResponse()

Well, re-encoding is needed sometimes (i.e. applying an watermark over an image while keeping the original untouched), but for the most simple of cases you can use: try: with open(valid_image, “rb”) as f: return HttpResponse(f.read(), content_type=”image/jpeg”) except IOError: red = Image.new(‘RGBA’, (1, 1), (255,0,0,0)) response = HttpResponse(content_type=”image/jpeg”) red.save(response, “JPEG”) return response