Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better abstraction of many-to-many Lookup attributes #258

Open
slinkp opened this issue Sep 28, 2012 · 1 comment
Open

Better abstraction of many-to-many Lookup attributes #258

slinkp opened this issue Sep 28, 2012 · 1 comment

Comments

@slinkp
Copy link
Contributor

slinkp commented Sep 28, 2012

Since m2m lookups are stored as a comma-separated string of ids,
you can't really create or modify values conveniently.
It would be nice if the AttributeDict made them look like a list of Lookup instances, or at least ids.

Then you wouldn't always have to write boilerplate code like:

        # Let's add one violation if it's not already there.
        ni = NewsItem.objects.get(...)
        violation_list = list(ni.attributes.get('violations', '').split(','))
        if str(violation.id) not in violation_list:
            violation_list.append(str(violation.id))
            ni.attributes['violations'] = ','.join(violation_list)

An even better solution would be to dispense with this silly comma-separated string entirely, and normalize the data properly, eg. with a many-to-many relationship between Lookups and Attributes. This would also mean we could get rid of the potentially slow regex search in NewsItemQuerySet.by_attribute().
It would mean more joins though.

@slinkp
Copy link
Contributor Author

slinkp commented Sep 28, 2012

Ticket imported from Trac:
http://developer.openblockproject.org/ticket/265
Reported by: slinkp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant