First steps getting eav-django running

307 views
Skip to first unread message

Janosch

unread,
Mar 4, 2010, 10:35:53 AM3/4/10
to eav-django

Hi,
as sugested by Andy, i want to share my experiences with eav-django
and invite everybody to discuss use cases, problems and tips.

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

Andy

unread,
Mar 4, 2010, 12:33:12 PM3/4/10
to eav-django
Janosh,

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

Janosch

unread,
Mar 4, 2010, 1:07:03 PM3/4/10
to eav-django

Hi Andy,
thanks for your reply, its working!
(with very small adjustment: i had to introduce a meta-class in the
fruitform for the model property)

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

Ken

unread,
Jan 22, 2014, 11:06:48 AM1/22/14
to eav-d...@googlegroups.com
Do you perhaps have a tutorial for getting the example working?

Ken

unread,
Mar 27, 2014, 5:02:30 AM3/27/14
to eav-d...@googlegroups.com
Hi Andy,
How does one create formsets in admin.py? If I do it the normal way I get two sets of fields. One is the well organized formsets and the next is all the attributes organized alphabetically. How do I get only one set of fields organized into fieldsets.

Thanks


On Thursday, 4 March 2010 17:35:53 UTC+2, Janosch wrote:

Ken

unread,
Mar 27, 2014, 5:05:37 AM3/27/14
to eav-d...@googlegroups.com
Here is a sample code of how I go about creating fieldsets. Please let me know what I should do.

# eav_fieldsets = (
    #         ('Patient History', {
    #         'classes' :['extrapretty','collapse'],
    #         'fields': (('pmh_dor', 'pmh_hiv', 'pmh_tb'),
           
    #         ('pmh_genitalherpes', 'pmh_heartfailure', 'pmh_ks',
    #         'pmh_lymphoma', 'pmh_malignancy', 'pmh_oralcandida', 'pmh_other',
    #         'pmh_zoster')),
           
           
           
           
    #         }),

Ken
Reply all
Reply to author
Forward
0 new messages