[Solved]-How to set up a django test server when using gunicorn?

2👍 I’ve read the code. Looking at LiveServerTestCase for inspiration makes sense but trying to cook up something by extending or somehow calling LiveServerTestCase is asking for trouble and increased maintenance costs. A robust way to run which looks like what LiveServerTestCase does is to create from unittest.TestCase a test case class with custom setUpClass … Read more

[Solved]-Celery @task doesn't work with instance methods

3👍 ✅ Celery has experimental support for using methods as tasks since version 3.0. The documentation for this is in celery.contrib.methods, and also mentions some caveats you should be aware of: http://docs.celeryproject.org/en/latest/reference/celery.contrib.methods.html Used this as reference 👤securecurve Poor performance of Django ORM with Oracle Source:stackexchange.com

[Solved]-Poor performance of Django ORM with Oracle

1👍 ✅ After working with our DBAs, it turned out that for some reason the Django get(upi=’xxxxxxxxxxxx’) queries didn’t use the database index. When the same query was rewritten using filter(upi=’xxxxxxxxxxxx’)[:1].get(), the query was fast. The get query was fast only with integer primary keys (it was string in the original question). FINAL SOLUTION create … Read more

[Solved]-Django dev server request.META has all my env vars

1👍 ✅ The request is constructed by the web server. By using the Django development environment, you are presumably using the Werkzeug web server. That’s why the request has options from the process environment, because that’s how Werkzeug constructs a request. 👤bignose Vagrant debugging python/django on Pycharm 2👍 I just ran into this as well … Read more

[Solved]-Vagrant debugging python/django on Pycharm

3👍 If you Let your PyCharm project configuration know about the project’s vagrant box Set up a remote interpreter of type Vagrant referencing the right python executable within the vagrant box Use that remote interpreter as your project’s python interpreter then you shouldn’t have to fuss around with ssh and with debugger command lines yourself … Read more

[Solved]-How to access the filtered queryset in django admin.SimpleListFilter

3👍 For BookAdmin class AuthorBestSeller(admin.SimpleListFilter): title = ‘Best selling authors’ parameter_name = ‘bestseller’ def queryset(self, request, queryset): if self.value(): return queryset.filter(author_id=self.value()) else: return queryset def lookups(self, request, model_admin): qs = model_admin.get_queryset(request) query_attrs = dict([(param, val) for param, val in request.GET.items()]) qs = qs.filter(**query_attrs) for book in qs.filter(is_bestseller=1): # or might be able to use yeild … Read more

[Solved]-Is there a django admin widget for adding multiple foreign keys with an inline through_model

3👍 ✅ Django source code (1.8 branch here, line 254) suggests that you can add your ForeignKey to radio_fields or raw_id_fields, resulting in a different widget. In this case, add the field name “Sound” to PlaylistMemberInline.raw_id_fields, consider adding it to PlaylistMemberInline.radio_fields. 👤Freek Wiekmeijer Include list_route methods in Django REST framework's API root Source:stackexchange.com

[Solved]-Include list_route methods in Django REST framework's API root

2👍 ✅ You could try to inherit from DefaultRouter which is responsible for api root view and redefine get_api_root_view method. class MyRouter(routers.DefaultRouter): def get_api_root_view(self): “”” Return a view to use as the API root. “”” api_root_dict = OrderedDict() list_name = self.routes[0].name for prefix, viewset, basename in self.registry: api_root_dict[prefix] = list_name.format(basename=basename) class APIRoot(views.APIView): _ignore_model_permissions = True … Read more

[Solved]-How to make Django Queryset that selects records with max value within a group

5👍 This Will help you from django.db.models import Count, Max MyClass.objects.values(‘my_integer’).annotate(count=Count(“my_integer”),latest_date=Max(‘created_ts’)) Data in table my_integer created_ts – ———– 1 2015-09-08 20:05:51.144321+00:00 1 2015-09-08 20:08:40.687936+00:00 3 2015-09-08 20:08:58.472077+00:00 2 2015-09-08 20:09:08.493748+00:00 2 2015-09-08 20:10:20.906069+00:00 Output [ {‘count’: 2, ‘latest_date’: datetime.datetime(2015, 9, 8, 20, 8, 40, 687936, tzinfo=<UTC>), ‘my_integer’: 1}, {‘count’: 2, ‘latest_date’: datetime.datetime(2015, 9, 8, 20, … Read more