Hi Mark,

On Sat, Apr 7, 2012 at 8:57 PM, Mark Phillips <m...@phillipsmarketing.biz>wrote:

>         Actually, just an ORDER BY FK, PK would produce the above... GROUP
>> BY would be used if you need something like counts/avg for each FK set.
>>
>
> I agree that if the data in the db was entered correctly in the first
> place, then just ORDER BY on the FK and PK would be sufficient. However, if
> the user needs to insert some data between sequence #3 and sequence #4,
> then I have to muck with the primary key of the table, which sounds
> dangerous.
>

I also have a similar problem in a project right now and have thought of 2
possible solutions. First is to use a FloatField or a DecimalField (o). Do
not reset it on every FK change. If the user wants to insert something
between records a & b, assign it a o value which is average of a.o and b.o.
If you are not expecting too many such insertions, it should work fine.

The other option is to store the ordering explicitly in the Foreign Key
model using a JSONField. This means that you will have to move all the work
involving ordering in the python layer which may or may not be suitable for
your case.

Currently I am going with option 2 for my case.

Regards,
Abhaya

-- 
-------------------------------------------------
blog: http://abhaga.blogspot.com
Twitter: http://twitter.com/abhaga
-------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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