foreign-key-relationship

Django 1.4 Multiple Databases Foreignkey relationship (1146, “Table 'other.orders_iorder' doesn't exist”)

血红的双手。 提交于 2021-02-19 06:10:49
问题 I have a Foreign Key from one model into another model in a differente database (I know I shouldn't do it but if I take care properly of Referential Integrity it shouldn't be a problem). The thing is that everything works fine...all the system does (relationships on any direction, the router takes care of it) but when I try to delete the referenced model (which doesn't have the foreign key attribute)...Django still wants to go throught the relationship to check if the relationship is empty,

Django 1.4 Multiple Databases Foreignkey relationship (1146, “Table 'other.orders_iorder' doesn't exist”)

纵然是瞬间 提交于 2021-02-19 06:09:25
问题 I have a Foreign Key from one model into another model in a differente database (I know I shouldn't do it but if I take care properly of Referential Integrity it shouldn't be a problem). The thing is that everything works fine...all the system does (relationships on any direction, the router takes care of it) but when I try to delete the referenced model (which doesn't have the foreign key attribute)...Django still wants to go throught the relationship to check if the relationship is empty,

Django 1.4 Multiple Databases Foreignkey relationship (1146, “Table 'other.orders_iorder' doesn't exist”)

让人想犯罪 __ 提交于 2021-02-19 06:07:38
问题 I have a Foreign Key from one model into another model in a differente database (I know I shouldn't do it but if I take care properly of Referential Integrity it shouldn't be a problem). The thing is that everything works fine...all the system does (relationships on any direction, the router takes care of it) but when I try to delete the referenced model (which doesn't have the foreign key attribute)...Django still wants to go throught the relationship to check if the relationship is empty,

Django 1.4 Multiple Databases Foreignkey relationship (1146, “Table 'other.orders_iorder' doesn't exist”)

自闭症网瘾萝莉.ら 提交于 2021-02-19 06:07:21
问题 I have a Foreign Key from one model into another model in a differente database (I know I shouldn't do it but if I take care properly of Referential Integrity it shouldn't be a problem). The thing is that everything works fine...all the system does (relationships on any direction, the router takes care of it) but when I try to delete the referenced model (which doesn't have the foreign key attribute)...Django still wants to go throught the relationship to check if the relationship is empty,

Storing “redundant” foreign keys to avoid joins

纵然是瞬间 提交于 2021-02-08 10:13:10
问题 I'm designing a database for a web application project and I came to the conclusion I may have few queries that will require a lot of joined tables to just make one check. I'm wondering how bad is it to store the foreign key somewhere on the way to decrease number of joins required for these queries? To give you an example of what I have at this moment: Service => Booking => Transaction => Wallet => BonusOffer I need to check whether the service has been bought with wallet associated with a

Storing “redundant” foreign keys to avoid joins

纵然是瞬间 提交于 2021-02-08 10:12:27
问题 I'm designing a database for a web application project and I came to the conclusion I may have few queries that will require a lot of joined tables to just make one check. I'm wondering how bad is it to store the foreign key somewhere on the way to decrease number of joins required for these queries? To give you an example of what I have at this moment: Service => Booking => Transaction => Wallet => BonusOffer I need to check whether the service has been bought with wallet associated with a

Django Shortcut nested foreign key

流过昼夜 提交于 2021-02-05 06:53:30
问题 Suppose I have the following in my models.py: class Book: pass class Part: book = models.ForeignKey(Book) class Chapter: part = models.ForeignKey(Part) number = models.IntegerField() I would like to do book = Book.objects.get(id=someID) chapters = Book.chapters.get(number=4) What is a clean way to do so? I thought of a Manager on the book class but it doest not seem to work for this case. Of course I could implement a method get_chapters on class book but i would like to avoid this. any ideas

Django Shortcut nested foreign key

被刻印的时光 ゝ 提交于 2021-02-05 06:53:24
问题 Suppose I have the following in my models.py: class Book: pass class Part: book = models.ForeignKey(Book) class Chapter: part = models.ForeignKey(Part) number = models.IntegerField() I would like to do book = Book.objects.get(id=someID) chapters = Book.chapters.get(number=4) What is a clean way to do so? I thought of a Manager on the book class but it doest not seem to work for this case. Of course I could implement a method get_chapters on class book but i would like to avoid this. any ideas

Setting up foreign key with an array of integers

自闭症网瘾萝莉.ら 提交于 2021-01-29 03:03:52
问题 I'm pretty new to working with SQL but I've come across this question on Stack Overflow for working with tags. Recommended SQL database design for tags or tagging This led me to create the following tables in my database: Doc --------------------------------------------------------------- | Doc Id (PK)(int) | Doc Title (varchar) | Doc Link (varchar) | --------------------------------------------------------------- | 1 | Printing | http://example.com | -----------------------------------------

Use of related field name in django template

旧街凉风 提交于 2020-07-11 04:28:31
问题 I have tow models like below: class A(models.Model): a = models.BooleanField(default=False) q = models.BooleanField(default=False) class B(models.Model): c = models.Foreignkey('A', related_name='bb') d = models.BooleanField(default=False) e = models.BooleanField(default=False) Here is my view: class Myview(ListView): model = A template_name = 'admin/layer.html' def get_context_data(self, *args, **kwargs): context = super(ListView, self).get_context_data(*args, **kwargs) context['mylist'] = A