无法按country__name对查询集进行排序

时间:2018-06-12 18:20:40

标签: django django-countries

我使用django-countries在我的django模型中设置国家/地区:

function mymodule_content_views_query_alter(ViewExecutable $view, 
QueryPluginBase $query)
{
//REWRITING FOR PLANNING ACTIVITY VIEW LOAD ACTIVITIES WHERE PERIOD ID 
IS GET["period"]
$periodid=\Drupal::request()->query->get('period');
foreach ($query->where as &$condition_group) {
    foreach ($condition_group['conditions'] as &$condition) {
        if ($condition['field'] == 
        'node__field_period_activity.field_period_activity_target_id = 
   :node__field_period_activity_field_period_activity_target_id ') {
            $condition = array(
                'field' => 'node__field_period_activity.field_period_activity_target_id = :node__field_period_activity_field_period_activity_target_id ',
                'value' => array(":node__field_period_activity_field_period_activity_target_id"=>$periodid),
                'operator' => 'formula',
            );
        }
    }
}

我希望# models.py from django_countries.fields import CountryField class MyModel(models.Model): title = models.CharField(max_length=255, blank=True) country = CountryField() 订购一个查询集,但显然是以下查询集:

country.name

不起作用:

MyModel.objects.live().order_by('country__name')

此外,显然 - 不可能使用模型Cannot resolve keyword 'name' into field. Join on 'country' not permitted.选项Meta

我可以通过以下方式在模板中订购: ordering 但更愿意在查询集中完成此操作。

亲爱的互联网,您是否知道如何通过{% for item in items.all|dictsort:"country.name" %}订购此查询集?

0 个答案:

没有答案