限制用户访问个人操作日志

时间:2018-09-19 05:56:41

标签: python django python-3.x

我在模型中有块及其文章的子集

NoMethodError in Orders#new

Showing /home/chiencong/depot/app/views/orders/_form.html.erb where line #2 raised:

undefined method `errors' for nil:NilClass

    <%= form_with(model: order, local: true) do |form| %>
       <% if order.errors.any? %>
         <div id="error_explanation">
           <h2><%= pluralize(order.errors.count, "error") %> prohibited this order from being saved:</h2>

           <ul>

Trace of template inclusion: app/views/orders/new.html.erb

我想限制用户访问记录我的每日日志记录的阻止操作。

class Block(models.Model):
    STATUS = (
        (1,  'normal'),
        (0, 'deleted'),
    )
    name = models.CharField("block name", max_length=100)
    desc = models.CharField("block description", max_length=100)
    admin = models.CharField("block admin", max_length=100)
    status = models.IntegerField(choices=STATUS)

class Article(models.Model):
    STATUS = (
        (1,  'normal'),
        (0, 'deleted'),
    )
    tags = models.ManyToManyField(Tag, blank=True)
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
    block = models.ForeignKey(Block, on_delete=models.CASCADE)
    title = models.CharField(max_length=100)

我通过条件检查完成了这样的任务:

In [40]: [b.name for b in Block.objects.all()]
Out[40]: ['Concepts', 'Reading', 'Coding', 'Action']

尽管如此,它似乎绝对是非正式的解决方案。 我怎么能用Django的内置装饰器或类似的东西完成它?

0 个答案:

没有答案