Re: How can I access attributes in intermediate class

2010-07-02 Thread cat in a tub
I found model inheritance may be a better solution: combine may model
into one (Similar to views combining tables in database)


Quote:

Model inheritance in Django works almost identically to the way normal
class inheritance works in Python. The only decision you have to make
is whether you want the parent models to be models in their own right
(with their own database tables), or if the parents are just holders
of common information that will only be visible through the child
models.

There are three styles of inheritance that are possible in Django.

   1. Often, you will just want to use the parent class to hold
information that you don't want to have to type out for each child
model. This class isn't going to ever be used in isolation, so
Abstract base classes are what you're after.
   2. If you're subclassing an existing model (perhaps something from
another application entirely) and want each model to have its own
database table, Multi-table inheritance is the way to go.
   3. Finally, if you only want to modify the Python-level behaviour
of a model, without changing the models fields in any way, you can use
Proxy models.


On Jun 29, 12:04 pm, Alexandre González <a...@mirblu.com> wrote:
> I was intrigued so I did it, I get this solution:
>
> from models import User, Group, Membership
>
> def example(request):
>     example_group_id = 1 #I create only one group to test, this is his id
>
>     group = Group.objects.get(pk=example_group_id)
>     for user in group.members.iterator(): #Get all user in the group
> throught the membership
>         membership = Membership.objects.get(person=user, group=group) #Get
> the membership object using the user and the group as keys
>         membership.date_joined # Now you can read your date_joined
>
> Perhaps it isn't the best way to do it, but it works :p
>
> I hope this helps you,
> Álex González
>
> On Tue, Jun 29, 2010 at 19:45, cat in a tub <luj...@gmail.com> wrote:
>
>
>
> > class User(models.Model):
> >    name = models.CharField(max_length=128)
>
> > class Group(models.Model):
> >    name = models.CharField(max_length=128)
> >    members = models.ManyToManyField(User, through='Membership')
>
> > class Membership(models.Model):
> >    person = models.ForeignKey(User)
> >    group = models.ForeignKey(Group)
> >    date_joined = models.DateField()
>
> > What if I want to access Membership.data_joined in Group class?
>
> > Thanks
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptxhttp://mirblu.com

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



Any implement of event bus in django

2010-07-02 Thread cat in a tub
Hi

I am wondering whether there is any implement of event bus (a
centralized control of sub/dist event via ajax sync).
Google use this design pattern in its ad-words by java. Does django
have similar solutions ?

Cheers
Homer

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



How can I access attributes in intermediate class

2010-06-29 Thread cat in a tub
class User(models.Model):
name = models.CharField(max_length=128)

class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(User, through='Membership')

class Membership(models.Model):
person = models.ForeignKey(User)
group = models.ForeignKey(Group)
date_joined = models.DateField()


What if I want to access Membership.data_joined in Group class?

Thanks

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



How to options by limited_choices_to ?

2010-06-22 Thread cat in a tub
Hi All,

I want to built a django application for hardware compatibility
testing
Some hardwares are compatible with certain mother board. And
attributes of each hardware are different (I use a ugly table to store
attributes), which are compatible with Hardware types, such as MEM as
SIZE, HDD has Firmware ver...

class HardwareType
...

class Hardware
type=models.ForeighKey('HardwareType')
hardware_type=models.ForeignKey('HardwareType',
limited_choice_to{'compatible_type':self.type})
attribute=ManyToManyField('hardwareAttribute')

class HardwareAttribute
compatible_type=models.ForeighKey('HardwareType')

I use limited_choice_to to limit the available options in the admin
(show compatible ones only)
But it doesn't work. The error is 'self is undefined ...'

Any one here has any idea how to to this ?

Thanking you in advance.

Homer

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