Tuesday, September 27, 2011

Sampling of the two models by matching fields.

Good day.
To the case.
There are some models (simplified form):

class Group (models.Model):
name = models.CharField ()

class Person (models.Model):
name = models.CharField ()
groups = models.ManyToManyField (Group)

class Event (models.Model):
name = models.CharField ()
groups = models.ManyToManyField (Group)

The task is to choose the names of all users and events having the
same group. For example:

Bob - Learning python
Bob - Writing hello world
Peter - Study python
Peter - Writing billing system

with

"Learning python" - Groups: 'Students'
"Writing a hello world" - Groups: 'Junior'
"Writing the billing system" - Groups: 'Experienced'

Bob - Groups: 'Students', 'Junior'
Peter - Groups: 'Students', 'Experienced'

If we'll try to solve the problem database way, groups would be easier
to store in the form of, for example, char fields, and select with a
simple condition:

where p.groups = e.groups

and then it becomes trivial (that is what happened in the past
implementation of the interface).

At the current moment that logic of the objects must implement to
django, and, faced with a problem I do not see how to solve it any
other way but commonplace 'for'.
I would be glad of any clue, including possible ways to change the
database structure.

Thanks for your attention.

--
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