[Solved]-Add fields to Django ModelForm that aren't in the model

1👍 If I were you, I would have used the customised Django-admin date/time widget(s) for entering date/time entries. Regarding form validation, make sure you pass the form associated with the request for it to show up form-based errors. (Sample code below) As for using inheritance, it would be a overkill for this use-case as it … Read more

[Solved]-Django handler500 as a Class Based View

2👍 I think its actually quite simple (in Django 1.7 with Python 3.4): views.py from django.http import HttpResponse from django.views.generic.base import View class Custom500View(View): def dispatch(self, request, *args, **kwargs): return HttpResponse(‘My custom django 500 page’) urls.py from .views import Custom500View handler500 = Custom500View.as_view() 👤Torsten Engelbrecht Multiple fields to the same DB column 0👍 I would … Read more

[Solved]-Multiple fields to the same DB column

2👍 It looks like a bug or oversight in django. As a workaround, you can try defining a custom manager which does a 2-stage prefetching. from django.db import models from django.db.models import Q from django.contrib.contenttypes.models import ContentType class PrefetchWorkaroundManager(models.Manager): def get_queryset(self): q = super(PrefetchWorkaroundManager, self).get_queryset() content_typeA = ContentType.objects.get_for_model(ModelA) content_typeB = ContentType.objects.get_for_model(ModelB) return q.filter(content_type__pk = content_typeA.id).prefetch_related(‘content_object’, … Read more

[Solved]-Returning id value after object creation with django-rest-framework

1👍 Here, DetectorSerializer inherits from ModelSerializer as well as your view inherits from generics ListCreateAPIView so when a POST request is made to the view, it should return the id as well as all the attributes defined in the fields of the Serializer. 👤Navneet Django Test Complaining about Fixture 1👍 Because it took me a … Read more

[Solved]-Django Test Complaining about Fixture

2👍 If: You are just interested in recovering the information from a json you generated before knowing this issue You don’t care about the data of administration logs You (or someone else) generated the json excluding auth.permission and contenttypes, using a command like: python manage.py dumpdata –exclude auth.permission –exclude contenttypes > db.json You may recover … Read more