如何使用get_context_data在基于分类的视图中添加分页

时间:2019-01-11 11:29:53

标签: django django-models django-forms django-templates django-views

我想向我的列表视图添加分页。我使用过paginated_by=10,但无法正常工作。请帮助我在模板中向我的视图添加分页。我应该在模板中放入什么HTML

View.py

class CompanyListView(LoginRequiredMixin, generic.TemplateView):
    template_name = 'superadmin/company/company.html'

    def get_context_data(self, **kwargs):   
        context = super(CompanyListView, self).get_context_data(**kwargs)
        context['companies'] = Company.objects.exclude(company_name='Apollo').exclude(company_is_deleted = True).annotate(number_of_company_users=Count('userprofile'))
        return context

1 个答案:

答案 0 :(得分:2)

您可以使用 using (FileStream fs = new FileStream("E:\\cnp.mp4", FileMode.Open, FileAccess.Read)) { dynamic parameters = new System.Dynamic.ExpandoObject(); parameters.upload_phase = "start"; parameters.file_size = fs.Length; var fileSize = (int)fs.Length; Console.WriteLine("file_size: {0}", fileSize); dynamic result = fb.Post("/" + FBAccountID + "/advideos", parameters); string upload_session_id = (string)result["upload_session_id"]; Console.WriteLine(""); Console.WriteLine("upload_session_id: {0}", (string)result["upload_session_id"]); Console.WriteLine("Video Id: {0}", (string)result["video_id"]); Console.WriteLine(""); Console.WriteLine("start_offset: {0}", (string)result["start_offset"]); Console.WriteLine("end_offset: {0}", (string)result["end_offset"]); int startOffset = int.Parse((string)result["start_offset"]); int endOffset = int.Parse((string)result["end_offset"]); int length = endOffset - startOffset; int i = 1; int totalBytesRead = 0; BinaryReader br = new BinaryReader(fs); while (length > 0) { if(endOffset == fileSize) { if (fileSize - totalBytesRead > endOffset - startOffset) { length = fileSize - totalBytesRead; } } byte[] buff = new byte[length]; buff = br.ReadBytes(length); totalBytesRead += buff.Length; //var gi = fs.Read(buff, startOffset, endOffset - startOffset); Console.WriteLine("buff length: {0}", buff.Length); Console.WriteLine("Total Bytes Read: {0}", totalBytesRead); dynamic parameters1 = new System.Dynamic.ExpandoObject(); parameters1.upload_phase = "transfer"; parameters1.upload_session_id = upload_session_id; parameters1.start_offset = startOffset; parameters1.video_file_chunk = new FacebookMediaObject { ContentType = "video/mp4", FileName = "cnp " + i + ".mp4" }.SetValue(buff); i++; dynamic result1 = fb.Post("/" + FBAccountID + "/advideos", parameters1); Console.WriteLine(""); Console.WriteLine("start_offset: {0}", (string)result1["start_offset"]); Console.WriteLine("end_offset: {0}", (string)result1["end_offset"]); startOffset = int.Parse((string)result1["start_offset"]); endOffset = int.Parse((string)result1["end_offset"]); length = endOffset - startOffset; } dynamic parameters2 = new System.Dynamic.ExpandoObject(); parameters2.upload_phase = "finish"; parameters2.upload_session_id = upload_session_id; parameters2.title = "Video title"; dynamic result2 = fb.Post("/" + FBAccountID + "/advideos", parameters2); Console.WriteLine("success: {0}", (string)result2["success"]); 代替ListView。 这就是方法。

TemplateView