FAQ
Hello everyone,

I'm trying to create a system that has 3 different user types:

Independent Agent, that basically is what it sounds like, and Django's User
Model works fine for this one.

But the catch comes from the other 2, because it also needs to support
agencies and agencies have sub-users...

I'm trying to figure out the best way to do this, currently I'm trying with
User profiles but don't really know if what I'm doing is correct, I'm doing
this:


class IndependentAgent(models.Model):
     user = models.OneToOneField(User)
     tipo_licencia = models.CharField(max_lenght=140)


class AgencyUser(models.Model):
     user = models.OneToOneField(User)
     agency = models.ForeignKey(User, related_name='Agency')


Can I do this? Like that user profile for Agency User would let me 'asign'
those users to their respective agencies so that later I can set my code
that those users can only see that agency's information?

Or would making groups be better to handle this kind of situations?

Appreciate any help I can get, thanks in advance


--
*Jorge Andres Vergara Ebratt*
*#SoftwareDeveloper (Or at least trying to be)*
*@javebratt*
*facebook.com/javebratt <http://facebook.com/javebratt>*

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Mario Gudelj at Jul 2, 2014 at 5:15 am
    Hey Jorge,

    I think you should extend the Abstract User instead of doing it the old
    way, which is creating that OneToOne relationship with a custom model. So,
    you'll end up with this:

    class IndependentAgent(AbstractBaseUser, PermissionsMixin):
         tipo_licencia = models.CharField(max_lenght=140)

    class AgencyUser(AbstractBaseUser, PermissionsMixin):
         agency = models.ForeignKey(User, related_name='Agency')

    This way you'll inherit all those awesome methods like setting the password
    etc. and attributes, like is_admin, but you can also simply add your own
    and dealing with this is much easier, than having to get the profile etc.

    Cheers,

    M


    On 2 July 2014 12:20, Jorge Andrés Vergara Ebratt wrote:

    Hello everyone,

    I'm trying to create a system that has 3 different user types:

    Independent Agent, that basically is what it sounds like, and Django's
    User Model works fine for this one.

    But the catch comes from the other 2, because it also needs to support
    agencies and agencies have sub-users...

    I'm trying to figure out the best way to do this, currently I'm trying
    with User profiles but don't really know if what I'm doing is correct, I'm
    doing this:


    class IndependentAgent(models.Model):
    user = models.OneToOneField(User)
    tipo_licencia = models.CharField(max_lenght=140)


    class AgencyUser(models.Model):
    user = models.OneToOneField(User)
    agency = models.ForeignKey(User, related_name='Agency')


    Can I do this? Like that user profile for Agency User would let me 'asign'
    those users to their respective agencies so that later I can set my code
    that those users can only see that agency's information?

    Or would making groups be better to handle this kind of situations?

    Appreciate any help I can get, thanks in advance


    --
    *Jorge Andres Vergara Ebratt*
    *#SoftwareDeveloper (Or at least trying to be)*
    *@javebratt*
    *facebook.com/javebratt <http://facebook.com/javebratt>*

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com
    <https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHqTbjmarOEX%2BJCPkTqyZq7YavkbdjQkmUPhjFeQS%3D5Ecetccg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Lachlan Musicman at Jul 2, 2014 at 5:16 am
    I would recommend Intermediate Models as a good solution for these
    type of weird situations

    https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

    Cheers
    L.
    On 2 July 2014 12:20, Jorge Andrés Vergara Ebratt wrote:
    Hello everyone,

    I'm trying to create a system that has 3 different user types:

    Independent Agent, that basically is what it sounds like, and Django's User
    Model works fine for this one.

    But the catch comes from the other 2, because it also needs to support
    agencies and agencies have sub-users...

    I'm trying to figure out the best way to do this, currently I'm trying with
    User profiles but don't really know if what I'm doing is correct, I'm doing
    this:


    class IndependentAgent(models.Model):
    user = models.OneToOneField(User)
    tipo_licencia = models.CharField(max_lenght=140)


    class AgencyUser(models.Model):
    user = models.OneToOneField(User)
    agency = models.ForeignKey(User, related_name='Agency')


    Can I do this? Like that user profile for Agency User would let me 'asign'
    those users to their respective agencies so that later I can set my code
    that those users can only see that agency's information?

    Or would making groups be better to handle this kind of situations?

    Appreciate any help I can get, thanks in advance


    --
    Jorge Andres Vergara Ebratt
    #SoftwareDeveloper (Or at least trying to be)
    @javebratt
    facebook.com/javebratt

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    The idea is that a beautiful image is frameable. Everything you need
    to see is there: It’s everything you want, and it’s very pleasing
    because there’s no extra information that you don’t get to see.
    Everything’s in a nice package for you. But sublime art is
    unframeable: It’s an image or idea that implies that there’s a bigger
    image or idea that you can’t see: You’re only getting to look at a
    fraction of it, and in that way it’s both beautiful and scary, because
    it’s reminding you that there’s more that you don’t have access to.
    It’s now sort of left the piece itself and it’s become your own
    invention, so it’s personal as well as being scary as well as being
    beautiful, which is what I really like about art like that.
    -----------------------------------------------------------------------------------------------------------
    Adventure Time http://theholenearthecenteroftheworld.com/

    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGBeqiPXRxw7t6qMdPNH_ECGwnK8DZrP7S1-5uzsoC3%2BtsNq5g%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Mike Dewhirst at Jul 2, 2014 at 6:59 am

    On 2/07/2014 3:16 PM, Lachlan Musicman wrote:
    I would recommend Intermediate Models as a good solution for these
    type of weird situations

    https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships +1
    Cheers
    L.
    On 2 July 2014 12:20, Jorge Andrés Vergara Ebratt wrote:
    Hello everyone,

    I'm trying to create a system that has 3 different user types:

    Independent Agent, that basically is what it sounds like, and Django's User
    Model works fine for this one.

    But the catch comes from the other 2, because it also needs to support
    agencies and agencies have sub-users...

    I'm trying to figure out the best way to do this, currently I'm trying with
    User profiles but don't really know if what I'm doing is correct, I'm doing
    this:


    class IndependentAgent(models.Model):
    user = models.OneToOneField(User)
    tipo_licencia = models.CharField(max_lenght=140)


    class AgencyUser(models.Model):
    user = models.OneToOneField(User)
    agency = models.ForeignKey(User, related_name='Agency')


    Can I do this? Like that user profile for Agency User would let me 'asign'
    those users to their respective agencies so that later I can set my code
    that those users can only see that agency's information?

    Or would making groups be better to handle this kind of situations?

    Appreciate any help I can get, thanks in advance


    --
    Jorge Andres Vergara Ebratt
    #SoftwareDeveloper (Or at least trying to be)
    @javebratt
    facebook.com/javebratt

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/53B3ADE0.8060604%40dewhirst.com.au.
    For more options, visit https://groups.google.com/d/optout.
  • Jorge Andrés Vergara Ebratt at Jul 2, 2014 at 9:53 am
    Hey Lachlan, I read the docs you sent me and I have a question, what if (in
    that example from the docs that uses Person, Group and Membership) I needed
    the Group class to be an user too? Like the Group was an user that can
    create, update and delete every user in itself and also all the information
    those users wirte to the DB... Would it still be a good approach and create
    a 'superuser' member of the group that can have those permissions? Or
    should I try something else like groups or extending BaseUser?


    2014-07-02 0:16 GMT-05:00 Lachlan Musicman <datakid@gmail.com>:
    I would recommend Intermediate Models as a good solution for these
    type of weird situations


    https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

    Cheers
    L.
    On 2 July 2014 12:20, Jorge Andrés Vergara Ebratt wrote:
    Hello everyone,

    I'm trying to create a system that has 3 different user types:

    Independent Agent, that basically is what it sounds like, and Django's User
    Model works fine for this one.

    But the catch comes from the other 2, because it also needs to support
    agencies and agencies have sub-users...

    I'm trying to figure out the best way to do this, currently I'm trying with
    User profiles but don't really know if what I'm doing is correct, I'm doing
    this:


    class IndependentAgent(models.Model):
    user = models.OneToOneField(User)
    tipo_licencia = models.CharField(max_lenght=140)


    class AgencyUser(models.Model):
    user = models.OneToOneField(User)
    agency = models.ForeignKey(User, related_name='Agency')


    Can I do this? Like that user profile for Agency User would let me 'asign'
    those users to their respective agencies so that later I can set my code
    that those users can only see that agency's information?

    Or would making groups be better to handle this kind of situations?

    Appreciate any help I can get, thanks in advance


    --
    Jorge Andres Vergara Ebratt
    #SoftwareDeveloper (Or at least trying to be)
    @javebratt
    facebook.com/javebratt

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com
    .
    For more options, visit https://groups.google.com/d/optout.


    --
    The idea is that a beautiful image is frameable. Everything you need
    to see is there: It’s everything you want, and it’s very pleasing
    because there’s no extra information that you don’t get to see.
    Everything’s in a nice package for you. But sublime art is
    unframeable: It’s an image or idea that implies that there’s a bigger
    image or idea that you can’t see: You’re only getting to look at a
    fraction of it, and in that way it’s both beautiful and scary, because
    it’s reminding you that there’s more that you don’t have access to.
    It’s now sort of left the piece itself and it’s become your own
    invention, so it’s personal as well as being scary as well as being
    beautiful, which is what I really like about art like that.

    -----------------------------------------------------------------------------------------------------------
    Adventure Time http://theholenearthecenteroftheworld.com/

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAGBeqiPXRxw7t6qMdPNH_ECGwnK8DZrP7S1-5uzsoC3%2BtsNq5g%40mail.gmail.com
    .
    For more options, visit https://groups.google.com/d/optout.


    --
    *Jorge Andres Vergara Ebratt*
    *#SoftwareDeveloper (Or at least trying to be)*
    *@javebratt*
    *facebook.com/javebratt <http://facebook.com/javebratt>*

    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAeX05Ew%2B%3DQ6CgLqtpVcwuvGs%3DQ7n0fNamthsSnT1MRxfrR0Aw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Lachlan Musicman at Jul 2, 2014 at 11:34 am
    Ah, ok, I see your problem is different - the Intermediate object
    probably isn't your friend.

    You can try the various levels of User, with various subclasses...

    http://www.django-rest-framework.org/api-guide/permissions

    Has some good ideas.

    cheers
    L.
    On 2 July 2014 19:52, Jorge Andrés Vergara Ebratt wrote:
    Hey Lachlan, I read the docs you sent me and I have a question, what if (in
    that example from the docs that uses Person, Group and Membership) I needed
    the Group class to be an user too? Like the Group was an user that can
    create, update and delete every user in itself and also all the information
    those users wirte to the DB... Would it still be a good approach and create
    a 'superuser' member of the group that can have those permissions? Or should
    I try something else like groups or extending BaseUser?


    2014-07-02 0:16 GMT-05:00 Lachlan Musicman <datakid@gmail.com>:
    I would recommend Intermediate Models as a good solution for these
    type of weird situations


    https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

    Cheers
    L.

    On 2 July 2014 12:20, Jorge Andrés Vergara Ebratt <javebratt@gmail.com>
    wrote:
    Hello everyone,

    I'm trying to create a system that has 3 different user types:

    Independent Agent, that basically is what it sounds like, and Django's
    User
    Model works fine for this one.

    But the catch comes from the other 2, because it also needs to support
    agencies and agencies have sub-users...

    I'm trying to figure out the best way to do this, currently I'm trying
    with
    User profiles but don't really know if what I'm doing is correct, I'm
    doing
    this:


    class IndependentAgent(models.Model):
    user = models.OneToOneField(User)
    tipo_licencia = models.CharField(max_lenght=140)


    class AgencyUser(models.Model):
    user = models.OneToOneField(User)
    agency = models.ForeignKey(User, related_name='Agency')


    Can I do this? Like that user profile for Agency User would let me
    'asign'
    those users to their respective agencies so that later I can set my code
    that those users can only see that agency's information?

    Or would making groups be better to handle this kind of situations?

    Appreciate any help I can get, thanks in advance


    --
    Jorge Andres Vergara Ebratt
    #SoftwareDeveloper (Or at least trying to be)
    @javebratt
    facebook.com/javebratt

    --
    You received this message because you are subscribed to the Google
    Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit

    https://groups.google.com/d/msgid/django-users/CAAeX05Gc6gnjdDi%3Dv%2B-n72mSi1JWdO1ecYUQORogvMifAw5o7w%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    The idea is that a beautiful image is frameable. Everything you need
    to see is there: It’s everything you want, and it’s very pleasing
    because there’s no extra information that you don’t get to see.
    Everything’s in a nice package for you. But sublime art is
    unframeable: It’s an image or idea that implies that there’s a bigger
    image or idea that you can’t see: You’re only getting to look at a
    fraction of it, and in that way it’s both beautiful and scary, because
    it’s reminding you that there’s more that you don’t have access to.
    It’s now sort of left the piece itself and it’s become your own
    invention, so it’s personal as well as being scary as well as being
    beautiful, which is what I really like about art like that.

    -----------------------------------------------------------------------------------------------------------
    Adventure Time http://theholenearthecenteroftheworld.com/

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAGBeqiPXRxw7t6qMdPNH_ECGwnK8DZrP7S1-5uzsoC3%2BtsNq5g%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.



    --
    Jorge Andres Vergara Ebratt
    #SoftwareDeveloper (Or at least trying to be)
    @javebratt
    facebook.com/javebratt

    --
    You received this message because you are subscribed to the Google Groups
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/django-users/CAAeX05Ew%2B%3DQ6CgLqtpVcwuvGs%3DQ7n0fNamthsSnT1MRxfrR0Aw%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.


    --
    The idea is that a beautiful image is frameable. Everything you need
    to see is there: It’s everything you want, and it’s very pleasing
    because there’s no extra information that you don’t get to see.
    Everything’s in a nice package for you. But sublime art is
    unframeable: It’s an image or idea that implies that there’s a bigger
    image or idea that you can’t see: You’re only getting to look at a
    fraction of it, and in that way it’s both beautiful and scary, because
    it’s reminding you that there’s more that you don’t have access to.
    It’s now sort of left the piece itself and it’s become your own
    invention, so it’s personal as well as being scary as well as being
    beautiful, which is what I really like about art like that.
    -----------------------------------------------------------------------------------------------------------
    Adventure Time http://theholenearthecenteroftheworld.com/

    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGBeqiOfNN6OuxpRtN3zEJDG%3DkCj%2Bx7Wm_MQtRG_5qJjY%3DLLDQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedJul 2, '14 at 2:20a
activeJul 2, '14 at 11:34a
posts6
users4
websitedjangoproject.com

People

Translate

site design / logo © 2022 Grokbase