Wednesday, July 14, 2010

Re: How to handle Jaywalking - parsing a comma-delimited value in field and do lookups (1,4,5,6...)

One idea that springs to mind is to add a property method to your
model that returns that self.group field as a list. With that list you
could add another property that returned all the actual group items.
Then write a custom admin view for add/change/view of that model which
works with the group instead. That way you can leave the data intact
but provide a management interface on top. Likewise you can in your
front end use your new propertys to work with the groups related to
that user. Whatever you do will probably involve a layer of work on
top.

So in your model I'd add something like:

@property
def group_list(self):
return self.group.split(',')

@property
def real_groups(self):
return Group.objects.all().filter(pk__in=self.group_list)

For writing a custom admin view this is to do with something a little
different but it's pretty comprehensive in terms of writing a
completely custom admin view:

http://elo80ka.wordpress.com/2009/10/28/using-a-formwizard-in-the-django-admin/

jaymz


On Jul 13, 12:10 pm, Snaky Love <snakyl...@googlemail.com> wrote:
> Hi,
>
> I have an "interesting" problem here - in a given mysql database
> scheme some sql wizard used comma-separated values in a text-field and
> with that values lookups have to be done. The data itself is simple
> numbers like 1,34,25,66,78,134 and so on. So what I have is something
> like this:
>
> id | username | groups         | more...
> ---------------------------------------------
> 1 | name        | 1,23,4,55,6  | ...
> 2 | name2      | 3,2,4,5        | ...
>
> The groups string can be very long. there is also a table "groups"
> with "id, name", as expected.
>
> Yes, this is bad design. No, I can not immediately change the design,
> I will try to, but atm I have to handle the situation as it is.
>
> Of course normally this would be solved with an intersection table and
> a many-to-many relation. For anybody interested: there is a book by
> Bill Karwin called "SQL Antipatterns" - he names the described design
> Jaywalking and it is the first antipattern in the book. I was
> surprised to find it in real life....
>
> So my question is: how to handle this with django? I really would
> like to use django to build a nice management interface on top of that
> tables, but currently I do not know how to go on with that jaywalking
> antipattern in my way.
>
> My first idea was to create my own intersection table - but the
> process of [re-]converting data does only work in a
> static environment - the data is heavily used and so
> transformations of tabledata would be neccassery on every request to
> mirror the live situation...too slow! So I am looking for a good way
> to
> implement some kind of layer that would translate this field for
> django into an intersaection table so that I can use models - will
> this work?
>
> What do you think? How to handle this?
>
> Thank you very much for your attention!
> Snaky

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate