>
> On Tue, Jul 19, 2011 at 2:58 PM, Andre Terra <andre...@gmail.com> wrote:
>
>> Hello, everyone
>>
>> Assume the following models (dpaste.com [1]):
>>
>> class Account(models.Model):
>>     """
>>     Account model for categorizing entries from each SAP import,
>>     and eventually sorting, grouping, filtering data.
>>     
>>     """
>>     code = models.CharField(max_length=255, primary_key=True)
>>     
>>     group = models.ForeignKey('AccountGroup', blank=True, null=True,
>>                               related_name='groups')
>>     
>>     description = models.CharField(max_length=512, blank=True, null=True)
>>     
>>     
>> class AccountGroup(models.Model):
>>     name = models.CharField(max_length=512, blank=True, null=True,
>>                             verbose_name=_('Name'))
>>     
>>     parent = models.ForeignKey('AccountGroup', blank=True, null=True,
>>                                related_name='children')
>>     
>>     is_subgroup = models.BooleanField(default=False, editable=False)
>>         
>>     def save(self, *args, **kwargs):
>>         self.is_subgroup = False
>>         
>>         if self.parent is not None:
>>             self.is_subgroup = True
>>             
>>         return super(AccountGroup, self).save(*args, **kwargs)
>>
>> I would like to be able to manually specify an order for AccountGroups in 
>> relation to their siblings, so that I can have a final result of something 
>> like the following pic (which describes a set of groups and accounts, with 
>> the latter being the rightmost, M000000000-format codes.
>>
>> http://img200.imageshack.us/img200/9423/groupsandaccounts.png
>>
>>
>> As you can see from the picture, accounts can be located under any number 
>> of groups, and neither Accounts nor AccountGroups are not sorted naturally.
>>
>> Short of using something like django-treebeard[3], how can I write a 
>> solution for this use case?
>>
>> Thanks in advance for all your help!
>>
>>
>> Cheers,
>> André Terra
>>
>>
>> [1] http://dpaste.com/hold/571566/
>> [2] 
>> https://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield
>> [3] https://tabo.pe/projects/django-treebeard/docs/1.52/
>>
>>
>
Well, a pre-order algorithm like MPTT - as provided by django-treebeard or 
django-mptt - *is* the way to go here. You don't say why you don't want to 
go down that route - what's your objection?
--
DR.

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

Reply via email to