How to order "links" in the Admin?

8 views
Skip to first unread message

Andre Lopes

unread,
Aug 9, 2011, 6:04:10 PM8/9/11
to django...@googlegroups.com
Hi,

I'm testing Django for my first project using it.

I have a model like this:
<code>
from django.db import models
import datetime

class Directory(models.Model):
website_name = models.CharField(max_length=200)
website_url = models.CharField(max_length=200)
website_position = models.IntegerField()
pub_date = models.DateTimeField('date published')
</code>

Basicaly this model is for storing URL's, but I need to order them,
and for that I use "website_position" to control if the link will be
at the top or at the end or in the middles...

My question is, there is a better way to control the positions of the
links? Django Admin have any feature that could help to deal with this
specific case?

Please let me know.

Best Regards,

Jian Chang

unread,
Aug 9, 2011, 9:43:42 PM8/9/11
to django...@googlegroups.com
you should figure out what it is based on to order these urls.

i use time stamp to order them.


2011/8/10 Andre Lopes <lopes8...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Andre Lopes

unread,
Aug 10, 2011, 4:25:59 AM8/10/11
to django...@googlegroups.com
Hi,

Thanks for the reply.

I use the field "website_position" to control the position of the url,
this is an Integer field.

The model I use is this:


<code>
from django.db import models
import datetime

class Directory(models.Model):
website_name = models.CharField(max_length=200)
website_url = models.CharField(max_length=200)
website_position = models.IntegerField()
pub_date = models.DateTimeField('date published')
</code>

Now I will populate the database with data:

<query output>
website_name | website_url | website_position | pub_date
Google | http://www.google.com | 1 |
10-08-2011
Yahoo | http://www.yahoo.com | 2 |
10-08-2011
Altavista | http://www.altavista.com | 3
| 10-08-2011
</query output>

The output of this will be: Google, Yahoo, Altavista

Another example: (Here I will reorder the links positions)

<query output>
website_name | website_url | website_position | pub_date
Google | http://www.google.com | 3 |
10-08-2011
Yahoo | http://www.yahoo.com | 2 |
10-08-2011
Altavista | http://www.altavista.com | 1
| 10-08-2011
</query output>

Ant the output will be: Altavista, Yahoo, Google

The thing here is that I control the positions of the links in Django
Admin with integers in the field "website_position". I'd like to know
if Django Admin have a better way to deal with this. There is possible
to control this with arrows to change the position of links, I click
in the up arrow and the link go up... I click in a down arrow and the
link goes down... This is possible in the Django Admin?


Best Regards,

creecode

unread,
Aug 10, 2011, 11:26:28 AM8/10/11
to django...@googlegroups.com
Hello Andre,

Try a Google search for "django admin drag drop reorder admin".  Several results there that might point you in the right direction.

I have used a variation on this Django Snippet < http://djangosnippets.org/snippets/1053/ > to do reordering in some of my projects.

Toodle-loooooooo...........
creecode

Eric Hutchinson

unread,
Aug 10, 2011, 12:01:51 PM8/10/11
to Django users
This is a meta option.

<code>
from django.db import models
import datetime
class Directory(models.Model):
website_name = models.CharField(max_length=200)
website_url = models.CharField(max_length=200)
website_position = models.IntegerField()
pub_date = models.DateTimeField('date published')

class Meta:
ordering=['website_position']
</code>

see: https://docs.djangoproject.com/en/1.3/ref/models/options/#ordering
> > 2011/8/10 Andre Lopes <lopes80an...@gmail.com>

Andre Lopes

unread,
Aug 11, 2011, 4:04:13 AM8/11/11
to django...@googlegroups.com
Thanks for the reply. What I need is a snipped like this one:
http://djangosnippets.org/snippets/1053/

Thanks a lot for your help.

Best Regards,

Reply all
Reply to author
Forward
0 new messages