Guest User

Untitled

a guest
Sep 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class Block(models.Model):
  2. STATUS = (
  3. (1, 'normal'),
  4. (0, 'deleted'),
  5. )
  6. name = models.CharField("block name", max_length=100)
  7. desc = models.CharField("block description", max_length=100)
  8. admin = models.CharField("block admin", max_length=100)
  9. status = models.IntegerField(choices=STATUS)
  10.  
  11. class Article(models.Model):
  12. STATUS = (
  13. (1, 'normal'),
  14. (0, 'deleted'),
  15. )
  16. tags = models.ManyToManyField(Tag, blank=True)
  17. owner = models.ForeignKey(User, on_delete=models.CASCADE)
  18. block = models.ForeignKey(Block, on_delete=models.CASCADE)
  19. title = models.CharField(max_length=100)
  20.  
  21. In [40]: [b.name for b in Block.objects.all()]
  22. Out[40]: ['Concepts', 'Reading', 'Coding', 'Action']
  23.  
  24. def article_detail(request, pk):
  25. article = get_object_or_404(Article, pk=pk)
  26. # sections and current_section
  27.  
  28. if article.block.name == "Action" and request.user.username not in administors:
  29. raise Http404("You are not authorized to read Section Action,I prefert to communicate on the topic action in persion.")
Add Comment
Please, Sign In to add comment