Monday, August 30, 2010

Re: Custom attributes in Django

Hi Sebastian,

I suppose you are trying to do something like this?

class CustomAttributes(models.Model):
name = models.CharField(max_length=30)
value = models.CharField(max_length=50)

class ObjectWithCustom(models.Model):
name = models.CharField(max_length=30)
attributes = models.ManyToManyField(CustomAttributes)

new_attr = o.attributes.create(name='custom_attr', value='value')

ObjectWithCustom.objects.filter(attributes__value='value')

For more info about many-to-many check out docs:
http://www.djangoproject.com/documentation/models/many_to_many/
Maybe describe in some detail what you are trying to accomplish (in
terms of resulting functionality), as this might not necessarily be
the best way to do it.

Cheers,

Béres Botond

On Aug 30, 5:54 pm, Sebastian Pawlus <sebastian.paw...@gmail.com>
wrote:
> Hi
>
> Maybe im looking in wrong places or maybe there is no application to
> cover functionality of carrying custom/admin defined attributes, or
> maybe it isn't even possible.
>
> Use Case could looks like
> Defining models
>
> from customr_attr import models
>
> class ObjectWithCustom(models.Model):
>      name = models.CharField(max_length=30)
>
> o = ObjectWithCustom.objects.create(name='test')
> o.custom_attr.create(name='custom_attr', value='value')
>
> >> o.custom_attr
>
> value
>
> >> ObjectWithCustom.objects.filter(custom_attr='value')
>
> [o]
>
> any ideas?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment