小编Dio*_*lva的帖子

how can I use pagination with django_filter

I got a problem with pagination after using django_filter in my TemplateView. Before use django_filter, my pagination was working normally but now it show all the items in every page, I've been looking on the internet but I didn't find a good solution for this. how can I fix it? thanks

my filter.py

class SnippetFilter(django_filters.FilterSet):
    area = []
    tecnology = Technology.objects.values('parent_area').distinct().order_by('parent_area_id')
    for a in tecnology:                                                                         
        area.append(a['parent_area']) 

    parent_area = django_filters.ModelMultipleChoiceFilter(queryset=ApplicationArea.objects.filter(id__in=area), widget=forms.CheckboxSelectMultiple)

    class Meta:
        model = Technology
        fields = ['title', 'category', 'kind', …
Run Code Online (Sandbox Code Playgroud)

django filter django-filter

3
推荐指数
1
解决办法
3097
查看次数

如何为 Django ModelForm 创建子表单

我在使用 ModelForm 添加 ManyToMany 字段时遇到问题,问题是我不知道如何创建子表单以将此数据添加到我的主表单。我想创建一个在单击按钮时保存的子表单,并且我希望选择保存的数据在主表单中使用。

我的模特

class Teste(models.Model):

   name = models.CharField(max_length=255)
   parent_institution_name = models.CharField(max_length=255)
   laboratory_departament = models.CharField(max_length=255, null=True, 
   blank=True, verbose_name="Laboratório")
   cep = models.CharField(max_length=255, verbose_name="Cep")
   cnpj = models.CharField(max_length=255, verbose_name="CNPJ")
   lat = models.FloatField(blank=True, null=True)
   lng = models.FloatField(blank=True, null=True)
   institution_name = models.CharField(max_length=255, null=False, 
   verbose_name="Nome da instituição")
   parent_institution_name = models.CharField(max_length=255, blank=True, 
   null=True, verbose_name="Nome da instituição vinculada")
   coordinator = models.CharField(max_length=255, verbose_name="Pessoa 
   Responsavel")
   email = models.CharField(max_length=255, verbose_name="E-mail")
   website = models.CharField(max_length=255, blank=True, null=True, 
   verbose_name="Website")
   rad_operating_time = models.IntegerField(verbose_name="Tempo de atuação 
   ")
   research_line = models.ManyToManyField('researcher.ResearchLines')
Run Code Online (Sandbox Code Playgroud)

我的 ModelForm 类 TestForm(forms.ModelForm): …

django modelform

1
推荐指数
1
解决办法
3248
查看次数

标签 统计

django ×2

django-filter ×1

filter ×1

modelform ×1