On 30 jan, 08:16, Kirill <[email protected]> wrote:
> Hello all!
>
> I have some logic problem.... I really don't understand how make model
> for this task:
>
> I have registered users (i want to use User class).
> Each registered user can create project (or group or blog) where he
> can invite another users
> So, how it's better to do model ?

It's just ordinary relational database modeling (hint : if you don't
have a clue about relational databases modelling, first find a good
resource on thsi topic). If we write it as text, we have something
like:

- a User owns zero, one or many PGB (=> ProjectOrGroupOrBlog)
- a PGB belongs to one User
- a User can be invited to zero, one or many PGB
- a PGB can have zero, one or many invited Users

IOW, you have two relationships between User and PGB:

- User "owns" PGB, with cardinality 1:N
- User "is invited to" PGB with cardinality N:N

The first one is expressed as a simple foreign key in PGB referencing
User. This is expressed in Django with a models.ForeignKey referencing
User. cf:
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

The seconds requires an association table User_PGB, with foreign keys
to User and PGB. The good news is that if you don't require any
additional field on this association table, Django's ORM can
automagically takes care of it using a models.ManyToManyField, cf:
http://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield

The result would look like:

class ProjectOrGroupOrBlog(models.Model):
    owner = models.ForeignKey(User)
    invited_users = models.ManyToManyField(User,
related_name='project_or_group_blog_set')

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

Reply via email to