fork download
  1. # models.py
  2. class Categories(TagBase):
  3. pass
  4.  
  5. class CategoriesTaggedItem(GenericTaggedItemBase):
  6. cat = models.ForeignKey(Categories)
  7.  
  8. class Manufacturer(TagBase):
  9. pass
  10.  
  11. class ManufacturerTaggedItems(GenericTaggedItemBase):
  12. man = models.ForeignKey(Manufacturer)
  13.  
  14.  
  15. class Product(models.Model):
  16.  
  17. #БлаБлаБла
  18.  
  19. tags = TaggableManager()
  20. manufacturer = TaggableManager(verbose_name='Manufacturer', through=ManufacturerTaggedItems, blank=True)
  21. categories = TaggableManager(verbose_name='Categories', through=CategoriesTaggedItem, blank=True)
  22.  
  23. def __str__(self):
  24. return self.name
  25.  
  26. #views.py
  27.  
  28. def product(request, product_id=1):
  29. args = {}
  30. args['product'] = Product.objects.get(id=product_id)
  31. #БлаБлаБла
  32.  
  33. return render_to_response('page.html', args)
  34.  
  35.  
  36. # page.html
  37.  
  38. #БлаБлаБла
  39.  
  40. {% for tag in product.tags.all %} #Эта часть работает
  41. {{tag.name}}
  42. {% endfor %}
  43.  
  44. {% for tag in product.categories.all %} #А вот так не робит
  45. {{tag.name}}
  46. {% endfor %}
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.4/py_compile.py", line 124, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap>", line 1532, in source_to_code
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "./prog.py", line 40
    {% for tag in product.tags.all %}  #Эта часть работает
     ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.4/py_compile.py", line 128, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 40
    {% for tag in product.tags.all %}  #Эта часть работает
     ^
SyntaxError: invalid syntax

stdout
Standard output is empty