no attrs

85 views
Skip to first unread message

zzart

unread,
Feb 18, 2012, 9:37:25 AM2/18/12
to eav-django
Playing with the example:
# django
from django.db import models

# eav
from eav.models import BaseChoice, BaseEntity, BaseSchema,
BaseAttribute


class Fruit(BaseEntity):
title = models.CharField(max_length=50)

@classmethod
def get_schemata_for_model(self):
return Schema.objects.all()

def __unicode__(self):
return self.title


class Schema(BaseSchema):
pass


class Choice(BaseChoice):
schema = models.ForeignKey(Schema, related_name='choices')


class Attribute(BaseAttribute):
schema = models.ForeignKey(Schema, related_name='attrs')
choice = models.ForeignKey(Choice, blank=True, null=True)

----------------------


>>> from grocery.models import *
>>> color = Schema.objects.create(
... title='Color',
... name='color',
... datatype=Schema.TYPE_TEXT)
>>> e = Fruit.objects.create(title='Apple', color='green')
>>> e.title
'Apple'
>>> e.color
'green'
>>> e.attrs.all()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/eav/models.py", line
233, in __getattr__
(self._meta.object_name, name))
AttributeError: Fruit does not have attribute named "attrs".
>>> e.save()
>>> e.attrs.all()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/eav/models.py", line
233, in __getattr__
(self._meta.object_name, name))
AttributeError: Fruit does not have attribute named "attrs".
>>> q = Fruit.objects.filter(color='green')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/eav/managers.py", line
55, in filter
qs = qs.filter(**lookups)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/
query.py", line 550, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/
query.py", line 568, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/
query.py", line 1194, in add_q
can_reuse=used_aliases, force_having=force_having)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/
query.py", line 1069, in add_filter
negate=negate, process_extras=process_extras)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/
query.py", line 1260, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'attrs' into field. Choices are:
id, title


django 1.3.1
django-autoslug - 1.5.0
django-view-shortcuts - 1.3.5
python 2.6

Am I missing something ?

Andy Mikhailenko

unread,
Feb 19, 2012, 6:02:37 AM2/19/12
to eav-d...@googlegroups.com
Hello Mariusz,

On 18 February 2012 20:37, zzart <mariusz.r...@gmail.com> wrote:
> Playing with the example:
> [...]


> Am I missing something ?

I guess you need a GenericRelation like in the tests[1] or something
in this vein.

By the way, I've just added a tox config to make sure that the tests
run under both Python 2.6 and 2.7, and they do, so the automated tests
are currently the best reference material. The "grocery shop" example
is only tested manually sometimes, and I won't call this testing :-)

[1] https://bitbucket.org/neithere/eav-django/src/f654bd8bd4af/eav/tests.py#cl-284

Good luck,
Andy

zzart

unread,
Feb 21, 2012, 5:37:08 AM2/21/12
to eav-django
hi Andy,Thanks for your quick replay. I have been playing with EAV and
i quite like it so thanks for making the effort. in models.py
shouldn't there be
    def get_choices(self):        """        Returns a queryset of
choice objects bound to this schema.        """        return
self.choice.all()
instead of current:
    def get_choices(self):        """        Returns a queryset of
choice objects bound to this schema.        """        return
self.choices.all()

??
If you don't mind i have one more question: I have categorised
Entities so i can generate a different  form (schema) depending on
Entity category.  My question is what do i override to filter out
schemas i don't need when generating a form ?

greets,




W dniu 19 lutego 2012 12:02 użytkownik Andy Mikhailenko
<neit...@gmail.com> napisał:Hello Mariusz,
On 18 February 2012 20:37, zzart <mariusz.r...@gmail.com>
wrote:> Playing with the example:> [...]> Am I missing something ?
I guess you need a GenericRelation like in the tests[1] or somethingin
this vein.
By the way, I've just added a tox config to make sure that the
testsrun under both Python 2.6 and 2.7, and they do, so the automated
testsare currently the best reference material. The "grocery shop"
exampleis only tested manually sometimes, and I won't call this
On 19 Lut, 12:02, Andy Mikhailenko <neith...@gmail.com> wrote:
> Hello Mariusz,
>
> On 18 February 2012 20:37, zzart <mariusz.raczyns...@gmail.com> wrote:
>
> > Playing with the example:
> > [...]
> > Am I missing something ?
>
> I guess you need a GenericRelation like in the tests[1] or something
> in this vein.
>
> By the way, I've just added a tox config to make sure that the tests
> run under both Python 2.6 and 2.7, and they do, so the automated tests
> are currently the best reference material. The "grocery shop" example
> is only tested manually sometimes, and I won't call this testing :-)
>
> [1]https://bitbucket.org/neithere/eav-django/src/f654bd8bd4af/eav/tests....
>
> Good luck,
> Andy

zzart

unread,
Feb 25, 2012, 6:34:50 PM2/25/12
to eav-django
this is what i was after - especially the get_schemata_for_instance
bit .. thanks anyway!

    @classmethod        def get_schemata_for_model(self):         
      return Schema.objects.all()
        def get_schemata_for_instance(self, qs):                
return qs.filter(category=self.category)





On 21 Lut, 11:37, zzart <mariusz.raczyns...@gmail.com> wrote:
> hi Andy,Thanks for your quick replay. I have been playing with EAV and
> i quite like it so thanks for making the effort. in models.py
> shouldn't there be
>     def get_choices(self):        """        Returns a queryset of
> choice objects bound to this schema.        """        return
> self.choice.all()
> instead of current:
>     def get_choices(self):        """        Returns a queryset of
> choice objects bound to this schema.        """        return
> self.choices.all()
>
> ??
> If you don't mind i have one more question: I have categorised
> Entities so i can generate a different  form (schema) depending on
> Entity category.  My question is what do i override to filter out
> schemas i don't need when generating a form ?
>
> greets,
>
> W dniu 19 lutego 2012 12:02 użytkownik Andy Mikhailenko
> <neith...@gmail.com> napisał:Hello Mariusz,
> On 18 February 2012 20:37, zzart <mariusz.raczyns...@gmail.com>
> wrote:> Playing with the example:> [...]> Am I missing something ?
> I guess you need a GenericRelation like in the tests[1] or somethingin
> this vein.
> By the way, I've just added a tox config to make sure that the
> testsrun under both Python 2.6 and 2.7, and they do, so the automated
> testsare currently the best reference material. The "grocery shop"
> exampleis only tested manually sometimes, and I won't call this
> testing :-)
> [1]https://bitbucket.org/neithere/eav-django/src/f654bd8bd4af/eav/tests....
Reply all
Reply to author
Forward
0 new messages