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

Filter attributes by entity? #10

Open
georgedorn opened this issue Nov 16, 2011 · 3 comments
Open

Filter attributes by entity? #10

georgedorn opened this issue Nov 16, 2011 · 3 comments

Comments

@georgedorn
Copy link

I have three different models that I want to use EAV with. I don't want to share any Attributes between them, and in fact want to have three different admin pages for managing each type of Attribute. I notice that the Attribute model doesn't have a foreign key to a ContentType, so the only way to filter attributes is to hardcode references to attribute names, which isn't an option for me as I have no idea what attributes will exist.

Is there another way to handle this, or would the best approach be to fork the project to add this feature? If so, is there any guidance you can give me for what other parts of django-eav I'd need to adapt?

@jashugan
Copy link

I needed the same feature. What I did was create a another model called Template which points to a ContentType and to which Attribute points to. There are several areas that you'll need to change EAV. The biggest one, by far, is the manager.py module. Currently, since, django-eav assumes that slug is unique in attribute, it can do the lookup and be confident it won't get multiple results. For example:

If you have two attributes with the slug test_date, you won't be able to do the following:

eav_m.Patient.objects.get(eav__test_date=date_var)

I've modified django-eav to support my changes by making my Template have a unique slug, so I can do the following:

eav_m.Patient.objects.get(blood_test__eav__test_date=date_var)
eav_m.Patient.objects.get(fasting_glucose_test__eav__test_date=date_var)

HTH

@georgedorn
Copy link
Author

I ended up forking the project to add a parent model field (a foreign key to ContentType), a custom manager to retrieve only those Attributes belonging to a parent, and some proxy models to make the Admin happy. I'm still working on it, but pushing out updates as I need them.

@jashugan
Copy link

Interesting... I've never used proxy models before. I noticed you haven't
touched the managers.py yet, are you planning on modifying it? You could
potentially still do it, as long as you specify app_label, model, and
attribute slug when filtering using eav. It could be potentially long
however.

On Tue, Dec 13, 2011 at 5:48 PM, George Dorn <
[email protected]

wrote:

I ended up forking the project to add a parent model field (a foreign key
to ContentType), a custom manager to retrieve only those Attributes
belonging to a parent, and some proxy models to make the Admin happy. I'm
still working on it, but pushing out updates as I need them.


Reply to this email directly or view it on GitHub:
#10 (comment)

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

No branches or pull requests

2 participants