我正在开发一个用户提交链接的Django项目,然后管理员/主持人可以接受或拒绝该链接。在我的模型中,默认情况下有一个名为status的属性Submitted
。我希望实现的是一个管理页面,主持人可以查看所有提交的链接并单击复选框,然后从下拉列表中选择一个值,将状态更改为Approved
或Denied
,类似于您在Django admin中删除条目所需的步骤。
这是我的models.py
:
class WebPage(models.Model):
STATUS_CHOICES = (
('Submitted', 'Submitted'),
('Approved', 'Approved'),
('Denied', 'Denied'),
('Scraped', 'Scraped'),
)
url = models.URLField()
title = models.CharField(max_length=250, null=True, blank=True)
stack = models.ForeignKey(Stack)
submitter = models.ForeignKey(User)
status = models.CharField(max_length=50, choices=STATUS_CHOICES, default='Submitted')
我的views.py
:
def admin_tools(request, stack_url):
context_dict = {}
stack = Stack.objects.get(url=stack_url)
context_dict['stack'] = stack
new_links_list = WebPage.objects.filter(stack=stack, status="Submitted")
context_dict['new_links_list'] = new_links_list
return render(request, 'stack/admin_page.html', context_dict)
最后是我的HTML:
<table class="table table-bordered">
<tr>
<th></th>
<th>Title</th>
<th>Submission Type</th>
<th>Submitted by</th>
</tr>
{% for link in new_links_list %}
<tr>
<td><input type="checkbox"></td>
<td><a href="{{ link.url }}"> {{ link.title }} </a></td>
<td>{{ link.link_type }}</td>
<td>{{ link.submitter }}</td>
</tr>
{% endfor %}
</table>
关于如何实现这一目标的任何想法?感谢