Re: How to establish foreign key contraints across models living in different applications
guillermooo wrote: > > I suppose you mean in terms of performance? Could you please elaborate > on the disadvantages? > They're not database-level foreign keys. So no db-level integrity checks. You also can't presently use them in an easy manner in more complex queries (aggregation). They might be a bit nonobvious to someone looking at the RDBMS level, not exactly typical db design. For some applications, you might also find they're "not generic enough" - django doesn't _require_ primary keys to be integers, but it tends to get assumed a lot - and each generic relation can only be generic across keys of one type. Really, I'd expect a lot of the time there could just be a modelling issue that could be sorted by a rethink. I started trying to use them for a row-level permissioning scheme, but it ended up easier to just use a foreign key field to a security descriptor table on every model I wanted to use row level permissioning for (turns out setting row-level permissions on other apps' models tends not to be very useful since those apps won't be written to support them...) --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to establish foreign key contraints across models living in different applications
Paul, > then generic keys may be the way to go. If however, you are simply > having one of your own apps depend on another I strongly suggest not > using generic foreign keys, they have drawbacks that could hinder you > down the road. I suppose you mean in terms of performance? Could you please elaborate on the disadvantages? Guillermo On Sep 27, 2:27 pm, pkenjorawrote: > Guillermo, > > Having one application depend on another is OK. If your are writing > a generic reusable application that other can download and plug in > then generic keys may be the way to go. If however, you are simply > having one of your own apps depend on another I strongly suggest not > using generic foreign keys, they have drawbacks that could hinder you > down the road. > > -Paul > > On Sep 27, 3:12 am, guillermooo > wrote: > > > > > Hi David, > > > I suppose that what you suggest would work too, but it would break the > > reusability of the Todo application. I think what I need is rather a > > GenericRelation/GenericForeignKey. Just found it in the docs. > > > Thanks, > > > Guillermo > > > On Sep 26, 10:21 pm, "djfis...@gmail.com" > > wrote: > > > > Guillermo, > > > > It is possible to have a model in one application have a foreign key > > > to another application as of Django 1.0. > > > > From:http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > > > --- > > > To refer to models defined in another application, you can explicitly > > > specify a model with the full application label. For example, if the > > > Manufacturer model above is defined in another application called > > > production, you'd need to use: > > > > class Car(models.Model): > > > manufacturer = models.ForeignKey('production.Manufacturer') > > > > This sort of reference can be useful when resolving circular import > > > dependencies between two applications. > > > --- > > > > Hopefully this is what you need. > > > > -David > > > > On Sep 26, 12:07 pm, Guillermo > > > wrote: > > > > > Hi all, > > > > > I have one app with a Project model and another app with a TodoItem > > > > model. How can I declare Project to be the foreign key of TodoItem? > > > > Or, rather, how can I make TodoItem accept an arbitrary model as > > > > foreign key? > > > > > Regards, > > > > > Guillermo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to establish foreign key contraints across models living in different applications
Guillermo, Having one application depend on another is OK. If your are writing a generic reusable application that other can download and plug in then generic keys may be the way to go. If however, you are simply having one of your own apps depend on another I strongly suggest not using generic foreign keys, they have drawbacks that could hinder you down the road. -Paul On Sep 27, 3:12 am, guillermooowrote: > Hi David, > > I suppose that what you suggest would work too, but it would break the > reusability of the Todo application. I think what I need is rather a > GenericRelation/GenericForeignKey. Just found it in the docs. > > Thanks, > > Guillermo > > On Sep 26, 10:21 pm, "djfis...@gmail.com" > wrote: > > > Guillermo, > > > It is possible to have a model in one application have a foreign key > > to another application as of Django 1.0. > > > From:http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > > --- > > To refer to models defined in another application, you can explicitly > > specify a model with the full application label. For example, if the > > Manufacturer model above is defined in another application called > > production, you'd need to use: > > > class Car(models.Model): > > manufacturer = models.ForeignKey('production.Manufacturer') > > > This sort of reference can be useful when resolving circular import > > dependencies between two applications. > > --- > > > Hopefully this is what you need. > > > -David > > > On Sep 26, 12:07 pm, Guillermo > > wrote: > > > > Hi all, > > > > I have one app with a Project model and another app with a TodoItem > > > model. How can I declare Project to be the foreign key of TodoItem? > > > Or, rather, how can I make TodoItem accept an arbitrary model as > > > foreign key? > > > > Regards, > > > > Guillermo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to establish foreign key contraints across models living in different applications
On Sat, Sep 26, 2009 at 3:21 PM, djfis...@gmail.comwrote: > It is possible to have a model in one application have a foreign key > to another application as of Django 1.0. It's always been possible to point relationships at models in other applications. The bit you're linking to is a special alternate syntax which lets you avoid circular import problems (where Model A in App A and Model B in App B both refer to each other -- Python doesn't let you import each one into the other's file), and that and *only* that was new as of 1.0. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to establish foreign key contraints across models living in different applications
Hi David, I suppose that what you suggest would work too, but it would break the reusability of the Todo application. I think what I need is rather a GenericRelation/GenericForeignKey. Just found it in the docs. Thanks, Guillermo On Sep 26, 10:21 pm, "djfis...@gmail.com"wrote: > Guillermo, > > It is possible to have a model in one application have a foreign key > to another application as of Django 1.0. > > From:http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > --- > To refer to models defined in another application, you can explicitly > specify a model with the full application label. For example, if the > Manufacturer model above is defined in another application called > production, you'd need to use: > > class Car(models.Model): > manufacturer = models.ForeignKey('production.Manufacturer') > > This sort of reference can be useful when resolving circular import > dependencies between two applications. > --- > > Hopefully this is what you need. > > -David > > On Sep 26, 12:07 pm, Guillermo > wrote: > > > > > Hi all, > > > I have one app with a Project model and another app with a TodoItem > > model. How can I declare Project to be the foreign key of TodoItem? > > Or, rather, how can I make TodoItem accept an arbitrary model as > > foreign key? > > > Regards, > > > Guillermo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to establish foreign key contraints across models living in different applications
Guillermo, It is possible to have a model in one application have a foreign key to another application as of Django 1.0. From: http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey --- To refer to models defined in another application, you can explicitly specify a model with the full application label. For example, if the Manufacturer model above is defined in another application called production, you'd need to use: class Car(models.Model): manufacturer = models.ForeignKey('production.Manufacturer') This sort of reference can be useful when resolving circular import dependencies between two applications. --- Hopefully this is what you need. -David On Sep 26, 12:07 pm, Guillermowrote: > Hi all, > > I have one app with a Project model and another app with a TodoItem > model. How can I declare Project to be the foreign key of TodoItem? > Or, rather, how can I make TodoItem accept an arbitrary model as > foreign key? > > Regards, > > Guillermo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to establish foreign key contraints across models living in different applications
Hi all, I have one app with a Project model and another app with a TodoItem model. How can I declare Project to be the foreign key of TodoItem? Or, rather, how can I make TodoItem accept an arbitrary model as foreign key? Regards, Guillermo --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---