Odevzdávátko: pláč v komentářích nad Django templates
This commit is contained in:
		
							parent
							
								
									0b9110cf68
								
							
						
					
					
						commit
						653a564bfd
					
				
					 1 changed files with 3 additions and 1 deletions
				
			
		|  | @ -173,7 +173,9 @@ class ReseniProblemuView(MultipleObjectTemplateResponseMixin, MultipleObjectMixi | ||||||
| 
 | 
 | ||||||
| 	def get_context_data(self, *args, **kwargs): | 	def get_context_data(self, *args, **kwargs): | ||||||
| 		ctx = super().get_context_data(*args, **kwargs) | 		ctx = super().get_context_data(*args, **kwargs) | ||||||
| 		# FIXME: Lepší by bylo předat groupby do template. | 		# XXX: Předat groupby do template nejde: https://stackoverflow.com/questions/6906593/itertools-groupby-in-a-django-template | ||||||
|  | 		# Django má {% regroup %}, ale ten potřebuje, aby klíč byl atribut položky: https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#regroup | ||||||
|  | 		# Takže rozbalíme groupby do slovníku klíč → seznam sami (dictionary comphrehension) | ||||||
| 		ctx['reseni_podle_deadlinu'] = {k: list(v) for k,v in groupby(ctx['object_list'], lambda r: deadline(r.cas_doruceni))} | 		ctx['reseni_podle_deadlinu'] = {k: list(v) for k,v in groupby(ctx['object_list'], lambda r: deadline(r.cas_doruceni))} | ||||||
| 		return ctx | 		return ctx | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Pavel "LEdoian" Turinsky
						Pavel "LEdoian" Turinsky