First of all, here are the additions i had to make to the instructions
on pypi ( http://pypi.python.org/pypi/eav-django ) to get the example
running:
- satisfy django-autoslug dependency
- define Choice(BaseChoice) with foreignkey "schema"
- add choice field to Attr
- add static get_schemata_for_model method to Fruit
After this, i can reproduce the given shell-session on pypi.
Problem is now, that the admin-interface is not working for the
entities (Fruit-Instances). I can only modify all normal properties,
but the eav attributes are not visible.
Can someone help me? Andy is under heavy load, so maybe someone else
is already using eav in his project with django admin?
Kind regards,
Janosch
thanks for your message. I've discovered that my short Readme-That-
Tries-To-Be-A-Tutorial was indeed incomplete. To get things work you
should modify your admin.py so that the standard ModelForm is replaced
with the dynamically constructed one:
from eav.forms import BaseDynamicEntityForm
class FruitForm(BaseDynamicEntityForm):
model = Fruit
class FruitAdmin(BaseEntityAdmin):
form = FruitForm
admin.site.register(Fruit, FruitAdmin)
You will probably want to move FruitForm to forms.py.
I don't think that this explicit way of defining the form is the best
approach. It is pretty verbose and it's clear that if a class inherits
from BaseEntityAdmin, it wants to enjoy the dynamically generated
entity form anyway. Maybe we should somehow modify the BaseEntityAdmin
so that it generates the appropriate form automatically if it isn't
defined.
Please drop a line about your progress. Sorry for the lack of a decent
tutorial. :-)
Cheers,
Andy
Dont think the need for a explicite FuitForm is a big deal for now,
knowing that i need it, it took me 1 minute to get it going.
I will continue exploring eav tomorrow, open questions for now are:
- how can be distinguished, wheter an attribute in a form is empty
("") or does not exist? I think i have to introduce a checkboxe for
every property.
- how can i control the ordering of the form fields? How can i control
the layout of the forms, but keep flexibility towards changing
datastructures
- could one make the Entity-class <-> Schema-class relation (currently
implemented by get_schemata_for_model) to be part of the data, instead
of beeing hardcoded? I have sketchy visions about something
configurable like multiple SchemaSets one can activate for specific
Entities.
So far i can say that this is a great enhancement to django (for
adequate projects) thanks a lot!!
Janosch