Re: Adding ManyToManyField to Django models
Michael, Your opinion on this makes sense and in the end I will probably just go with the wrapper approach, since it probably won't make that much of a difference anyways. My biggest qualm is that I'm trying to put together a strong foundation for the projects I'm working on and feel like this is not the best, but yes I understand why it's like this. The other option you brought up about pulling the auth code will probably get hairy (as you already pointed out). The ModelInheritance stuff does look interesting! Thanks for the input. Discussing stuff like this always helps define the scope of the tools and how to use them... I'm sure I would've wanted to do something similar at some point in the future with my own models and it always helps to know what the boundaries are (at least for now). Mike. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
On Tue, 2008-03-04 at 13:06 -0800, Michael Irani wrote: > I was wondering if it's possible to add a ManyToManyField onto a > prebuilt Django model such as User... I know that it would look like > this if I were to have created the model myself: > class User(models.Model): > watch = models.ManyToManyField('self', null=True, blank=True) > > I'm unsure how to add features to prebuilt models and wasn't even sure > if that was possible. Probably not such a great idea, since you aren't in control of any updates that might happen to the User model. It's the standard problem that if you change Django's source, that's fine, but then you have to remember to make sure your changes work with any updates we might happen to make to that code (we aren't about to add any new fields or anything, but extra Python code might be added, for example). A better approach would be to create your own many-to-many lookalike structure by creating the intermediate model with foreign keys pointing to User and whatever else you want (I guess also User in your case). That model is entirely under your control and won't require changing Django's source. Regards, Malcolm -- If Barbie is so popular, why do you have to buy her friends? http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
Michael; Think of it this way: the auth model is just one way to provide authentication into your architecture. It wouldn't make much sense to have too much more information about the person inside of this model. There is an effort to try to be able to extend models, but as far as I know it has been a difficult forge forward because databases don't work that way. The tie to another model is perfectly natural. As I am still thinking about this you wouldn't want to inherit the code anyway. If you want the cleanest implementation of your code you wouldn't want to have 2 different types (or the possibility thereof) of authentication. What I was saying in my first post is that you don't need to use any of the contrib applications. In fact, you can go ahead and look directly into the auth code and try to rewrite it with all the extras that you would like to put into it. I personally think you would be making yourself crazy just to save a table in your database, but if that is your cup of tea... Evert, take a look at the Model Inheritance branch: http://code.djangoproject.com/wiki/ModelInheritance it looks exciting, but a huge undertaking for whoever is working on it. I would be exciting to see and could save a lot of application code really. It definatly doesn't look like it would be ready before 1.0 On Tue, Mar 4, 2008 at 10:21 PM, Michael Irani <[EMAIL PROTECTED]> wrote: > > One thing I dislike about the approach that's being pushed by the > community, which is to have a one-to-one relationship between > auth.User and your own 'Profile' model (or whatever you want to call > it) adding all the functionality and relationships to the user-created > Model is a bit much. I mean yes it's convenient to use auth.User's > prebuilt functionality, but if you're building for the future and want > to start off in the right place, this method kind of starts your code > in an awkward place. The data model with this approach just feels > wrong... The right way to do it is to have two different tables link > to eachother and have the database make the bindings for you. I know > this simplifies the code a lot and that the DB will probably do a good > job with this lookup, but still seems a little awkward to me... > > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
One thing I dislike about the approach that's being pushed by the community, which is to have a one-to-one relationship between auth.User and your own 'Profile' model (or whatever you want to call it) adding all the functionality and relationships to the user-created Model is a bit much. I mean yes it's convenient to use auth.User's prebuilt functionality, but if you're building for the future and want to start off in the right place, this method kind of starts your code in an awkward place. The data model with this approach just feels wrong... The right way to do it is to have two different tables link to eachother and have the database make the bindings for you. I know this simplifies the code a lot and that the DB will probably do a good job with this lookup, but still seems a little awkward to me... --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
Evert, the situation is that I was trying to use the auth.User as my model and wanted to have it point to itself. Thereby not having my own model at all. I was curious as well about being able to subclass a prebuilt model, but from the reactions I've gotten towards this, it doesn't seem to be an option... --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
> I was wondering if it's possible to add a ManyToManyField onto a > prebuilt Django model such as User... I know that it would look like > this if I were to have created the model myself: > class User(models.Model): > watch = models.ManyToManyField('self', null=True, blank=True) > > I'm unsure how to add features to prebuilt models and wasn't even sure > if that was possible. Cannot you use a model with a ForeignKey to whatever prebuilt model you'd like to use? Cf using a home-made user model for authentication that ties into the prebuilt User. I would be curious, though, whether you can actually subclass a prebuilt model; my guess is not, and that it messes up the database tables, but that would be an interesting option otherwise. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
The amazing thing about Django contrib is that, in general, it uses the same features as are available to you in your models. So there is no reason that you need to even install the auth system. You could copy the code out of django.contrib.auth and customize it as you see fit. The only thing is that code is tested and really complex and might be doing things that you haven't even thought about, so you might be looking at a project that is more complicated than you really want it to be. The nice thing about auth is that it gives you a built in function to add a profile to a user. This might be the best solution for you. Check out the django book here: http://www.djangobook.com/en/1.0/chapter12/#cn222 On Tue, Mar 4, 2008 at 4:06 PM, Michael Irani <[EMAIL PROTECTED]> wrote: > > I was wondering if it's possible to add a ManyToManyField onto a > prebuilt Django model such as User... I know that it would look like > this if I were to have created the model myself: > class User(models.Model): > watch = models.ManyToManyField('self', null=True, blank=True) > > I'm unsure how to add features to prebuilt models and wasn't even sure > if that was possible. > > Thanks, > Mike. > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
Yep here's a good article on it: http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ On Mar 4, 5:36 pm, Michael Irani <[EMAIL PROTECTED]> wrote: > I got some help on IRC and here's the conclusion. There is no way to > add that mapping from auth.User to itself without hacking the django > code, so what needs to happen is that I add a wrapper Model such as > 'Profile' and add the ManyToManyField to 'Profile'. Thereby the > mappings will happen within the 'Profile' models. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Adding ManyToManyField to Django models
I got some help on IRC and here's the conclusion. There is no way to add that mapping from auth.User to itself without hacking the django code, so what needs to happen is that I add a wrapper Model such as 'Profile' and add the ManyToManyField to 'Profile'. Thereby the mappings will happen within the 'Profile' models. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Adding ManyToManyField to Django models
I was wondering if it's possible to add a ManyToManyField onto a prebuilt Django model such as User... I know that it would look like this if I were to have created the model myself: class User(models.Model): watch = models.ManyToManyField('self', null=True, blank=True) I'm unsure how to add features to prebuilt models and wasn't even sure if that was possible. Thanks, Mike. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---