使用django-admin界面订购项目 [英] Order items with the django-admin interface

查看:106
本文介绍了使用django-admin界面订购项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个如下的django模型:

 类问题(models.Model):
order = models.IntegerField('Position')
question = models.CharField(max_length = 400)
answer = models.TextField()
published = models.BooleanField()

def __unicode __(self):
return self.question

在我看来我显示所有按订单字段升序排列的问题。



我的问题是:是否有一个简单的方法来编辑django管理界面中的订单字段?现在我必须去编辑问题,而不是在订单字段中查找数字,甚至可以重新排列所有其他项目。我真正想要的是在管理页面上列出所有问题的一些上下。



可以吗?

解决方案

当然,这是一个admin.py文件的示例,其中有上下文件链接来更改项目顺序:
https://github.com/alexvasi/django-simplemenu/blob/master/simplemenu/admin .py



基本上,你只需要覆盖 get_urls 方法添加您的自定义视图( move_up move_down 在这个例子中)



更有名的例子是 django-treemenus ,但是还有一些额外的代码来支持旧版本的django。


Lets say I have a django model looking like this:

class question(models.Model):
  order = models.IntegerField('Position')
  question = models.CharField(max_length= 400)
  answer = models.TextField()
  published = models.BooleanField()

  def __unicode__(self):
    return self.question

In my view I show all of the questions ordered ascending by the order field.

My question is: Is there an easy way to edit the order field in the django admin interface? Right now I have to go to edit the Question, than look up what number to put in the order field and maybe even reorder all the other items. What i really want would be some "up and down"-arrows on the admin page where all the questions are listed.

Is that possible?

解决方案

Sure, here is an example of admin.py file with up and down links to change items order: https://github.com/alexvasi/django-simplemenu/blob/master/simplemenu/admin.py

Basically, you just need to override get_urls method to add your custom views (move_up and move_down in this example).

More famous example would be django-treemenus, but there is some extra code to support older versions of django.

这篇关于使用django-admin界面订购项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆