Ordered list of objects?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Ordered list of objects?

Nathan R. Yergler-4

I'm working on an app for a client, and one of the requirements is
that they be able to re-order objects in the admin interface.  I know
exactly how I'd do with with an object database, but the ideas I've
come up with for doing it with Django all involve using some tracking
field, and then updating that to contain the relative order of
objects.

So... am I missing something obvious here that will let me do with
with a minimal amount of pain?

Thanks,

Nathan

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

Reply | Threaded
Open this post in threaded view
|

Re: Ordered list of objects?

atilla-3

On 04/04/07, Nathan R. Yergler <[hidden email]> wrote:

>
> I'm working on an app for a client, and one of the requirements is
> that they be able to re-order objects in the admin interface.  I know
> exactly how I'd do with with an object database, but the ideas I've
> come up with for doing it with Django all involve using some tracking
> field, and then updating that to contain the relative order of
> objects.
>
> So... am I missing something obvious here that will let me do with
> with a minimal amount of pain?
>
> Thanks,
>
> Nathan

What kind of ordering does it have to be and on what amount of items?
Perhaps it could be useful to create a separate Model that defines the
order of items, with a relation to the actual model that defines the
objects themselves. The biggest issue is how to create usable controls
that define the ordering, which is not always a simple thing to
implement.

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

Reply | Threaded
Open this post in threaded view
|

Re: Ordered list of objects?

Nathan R. Yergler-4

On 4/4/07, Atilla <[hidden email]> wrote:

>
> On 04/04/07, Nathan R. Yergler <[hidden email]> wrote:
> >
> > I'm working on an app for a client, and one of the requirements is
> > that they be able to re-order objects in the admin interface.  I know
> > exactly how I'd do with with an object database, but the ideas I've
> > come up with for doing it with Django all involve using some tracking
> > field, and then updating that to contain the relative order of
> > objects.
> >
> > So... am I missing something obvious here that will let me do with
> > with a minimal amount of pain?
> >
> > Thanks,
> >
> > Nathan
>
> What kind of ordering does it have to be and on what amount of items?
> Perhaps it could be useful to create a separate Model that defines the
> order of items, with a relation to the actual model that defines the
> objects themselves. The biggest issue is how to create usable controls
> that define the ordering, which is not always a simple thing to
> implement.

Arbitrary ordering of dozensis it  of items, so I'm not sure an
external model would help.


>
> >
>

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

Reply | Threaded
Open this post in threaded view
|

Re: Ordered list of objects?

EBMLucki@gmail.com

I don't know if this is the "right" solution or not. In my home grown
framework I've got a doubly linked list implementation.

My intention in Django is to write an application Ordered_List that
would be a functioning doubly linked list with minimal data fields
(currently just a name for each list to keep me sane during testing).
I'm thinking that I could import from this app and sub class from it
without having it in INSTALLED_APPS. To be able to mix-in arbitrary
ordering with any other model.

Brand new to Django, but if it goes well I'll post the code.

If someone has a better/easier solution feel free to share it.

--Lucki

On Apr 4, 9:57 am, "Nathan R. Yergler" <[hidden email]> wrote:

> On 4/4/07, Atilla <[hidden email]> wrote:
>
>
>
>
>
> > On 04/04/07, Nathan R. Yergler <[hidden email]> wrote:
>
> > > I'm working on an app for a client, and one of the requirements is
> > > that they be able to re-order objects in the admin interface.  I know
> > > exactly how I'd do with with an object database, but the ideas I've
> > > come up with for doing it with Django all involve using some tracking
> > > field, and then updating that to contain the relative order of
> > > objects.
>
> > > So... am I missing something obvious here that will let me do with
> > > with a minimal amount of pain?
>
> > > Thanks,
>
> > > Nathan
>
> > What kind of ordering does it have to be and on what amount of items?
> > Perhaps it could be useful to create a separate Model that defines the
> > order of items, with a relation to the actual model that defines the
> > objects themselves. The biggest issue is how to create usable controls
> > that define the ordering, which is not always a simple thing to
> > implement.
>
> Arbitrary ordering of dozensis it  of items, so I'm not sure an
> external model would help.
>
>


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

Reply | Threaded
Open this post in threaded view
|

Re: Ordered list of objects?

EBMLucki@gmail.com

I've got the solution, you can download it here:
http://purplesquirrelgroup.com/order_list.tar.gz

Here's the readme:

To use these models you will want to do the following:

For your Collection class:

from order_list.models import Order_List
from django.db import models

class Collection( Order_List, models.Model):
        name = models.CharField('name', maxlength=80)  #Feel free to
customize Maxlength

# I think there should be a better way to do this, but if you want to
use the
# can_reorder permision from the base class you'll need to do this:

        class Meta:
                permissions = Order_List.Meta.permissions


And for your Item class:

from order_list.models import Order_List_Item
from django.db import models

class Item(Order_List_Item, models.Model):
        # This /must/ be called list, and relate_name /must/ be
'_items'
        list = models.ForeignKey(Collection, verbose_name='collection
item', related_name='_items')
        _next = models.ForeignKey('self', verbose_name=_("next"),
null=True, blank=True, related_name='_prev')

        # I like to do this:
        def _get_collection(self):
                return self.list
        collection = property(_get_collection)


By applying this skelleton to any model you can make it arbitrarily
ordered. When you create new objects other then the first in
Collection be sure you use insert_before or insert_after with an
existing item rather then just save to preserve list sanity.


On Apr 20, 3:59 pm, "[hidden email]" <[hidden email]> wrote:

> I don't know if this is the "right" solution or not. In my home grown
> framework I've got a doubly linked list implementation.
>
> My intention in Django is to write an application Ordered_List that
> would be a functioning doubly linked list with minimal data fields
> (currently just a name for each list to keep me sane during testing).
> I'm thinking that I could import from this app and sub class from it
> without having it in INSTALLED_APPS. To be able to mix-in arbitrary
> ordering with any other model.
>
> Brand new to Django, but if it goes well I'll post the code.
>
> If someone has a better/easier solution feel free to share it.
>
> --Lucki
>
> On Apr 4, 9:57 am, "Nathan R. Yergler" <[hidden email]> wrote:
>
> > On 4/4/07, Atilla <[hidden email]> wrote:
>
> > > On 04/04/07, Nathan R. Yergler <[hidden email]> wrote:
>
> > > > I'm working on an app for a client, and one of the requirements is
> > > > that they be able to re-order objects in the admin interface.  I know
> > > > exactly how I'd do with with an object database, but the ideas I've
> > > > come up with for doing it with Django all involve using some tracking
> > > > field, and then updating that to contain the relative order of
> > > > objects.
>
> > > > So... am I missing something obvious here that will let me do with
> > > > with a minimal amount of pain?
>
> > > > Thanks,
>
> > > > Nathan
>
> > > What kind of ordering does it have to be and on what amount of items?
> > > Perhaps it could be useful to create a separate Model that defines the
> > > order of items, with a relation to the actual model that defines the
> > > objects themselves. The biggest issue is how to create usable controls
> > > that define the ordering, which is not always a simple thing to
> > > implement.
>
> > Arbitrary ordering of dozensis it  of items, so I'm not sure an
> > external model would help.


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