Esempio n. 1
0
    def test_is_m2m_for_chained_charfield(self):
        try:
            from django.apps import apps
            get_model = apps.get_model
        except ImportError:
            from django.db.models.loading import get_model

        # should return false
        self.assertEqual(is_m2m(get_model('test_app', 'TagResource'), 'kind'), False)
Esempio n. 2
0
    def test_is_m2m_for_chained_charfield(self):
        try:
            from django.apps import apps
            get_model = apps.get_model
        except ImportError:
            from django.db.models.loading import get_model

        # should return false
        self.assertEquals(is_m2m(get_model('test_app', 'TagResource'), 'kind'), False)
Esempio n. 3
0
def filterchain(request, app, model, field, foreign_key_app_name, foreign_key_model_name,
                foreign_key_field_name, value, manager=None):
    model_class = get_model(app, model)
    m2m = is_m2m(model_class, field)
    keywords = get_keywords(field, value, m2m=m2m)
    # filter queryset using limit_choices_to
    limit_choices_to = get_limit_choices_to(foreign_key_app_name, foreign_key_model_name, foreign_key_field_name)
    queryset = get_queryset(model_class, manager, limit_choices_to)

    try:
        queryset = queryset.for_user(request.session['crm_user_id'])
    except AttributeError:
        pass  # There's no `for_user(user_id)` method in current manager

    results = queryset.filter(**keywords)

    # Sort results if model doesn't include a default ordering.
    if not getattr(model_class._meta, 'ordering', False):
        results = list(results)
        sort_results(results)

    serialized_results = serialize_results(results)
    return JsonResponse(serialized_results, safe=False)
Esempio n. 4
0
 def test_is_m2m_for_chained_charfield(self):
     # should return false
     self.assertEqual(
         is_m2m(apps.get_model("test_app", "TagResource"), "kind"), False)