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.
>
> >
>
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" <nat...@yergler.net> wrote:
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.