Re: how to descript the many to one relationship in model when there are more than 1 tables

2015-08-06 Thread Javier Guerra Giraldez
On Thu, Aug 6, 2015 at 8:18 AM, Holland_zwz wrote: > But i am not got the main point. The problem is the table C's oid column > data comes from A or B. I don't think SQL works that way. at least, it's very much against any normalization guideline. -- Javier -- You

Re: how to descript the many to one relationship in model when there are more than 1 tables

2015-08-06 Thread Holland_zwz
Hi James, Thanks for reply. But i am not got the main point. The problem is the table C's oid column data comes from A or B. I think this is not same as many-to-many relationships. Thanks -hollandz 在 2015年8月6日星期四 UTC+8下午6:14:25,James Schneider写道: > > You are probably looking for a

Re: how to descript the many to one relationship in model when there are more than 1 tables

2015-08-06 Thread James Schneider
You are probably looking for a many-to-many relationship using an intermediary table: https://docs.djangoproject.com/en/1.8/topics/db/models/#intermediary-manytomany -James On Aug 6, 2015 3:06 AM, "Holland_zwz" wrote: > Sometimes table have more than one foreign key

how to descript the many to one relationship in model when there are more than 1 tables

2015-08-06 Thread Holland_zwz
Sometimes table have more than one foreign key reference to other tables. Then how to descript it in model? For eg: Table A: create table A ( oid varchar(10) not null, pid varchar(10) not null, color varchar(20)

Re: best way to define a many-to-one relationship using FreeRadius' existing DB schema

2011-04-01 Thread yolabingo
Solved - you do it like this: class WifiUser(models.Model): username = models.CharField( max_length=64, unique=True) --snip-- class RadiusAccounting(models.Model): radacctid = models.BigIntegerField(primary_key=True, editable=False) username = models.CharField(max_length=192)

best way to define a many-to-one relationship using FreeRadius' existing DB schema

2011-03-31 Thread yolabingo
bunch of cool radius info logged per session --snip-- So the radacct.username == WifiUser.username - but that is all I've got to associate these two tables. Can I set up some customized version of this Many-to-One relationship - class RadiusAccounting(models.Model): wifiuser = models.

Re: Custom linking of models in many-to-one relationship

2009-09-27 Thread kmike
This looks like django's generic relations ('Content types' in documentation). `select_related` for generic related models is not supported in django. So you should retreive all Notes associated with Account manually. If there are several Accounts you still can fetch all data in 2 queries using

Custom linking of models in many-to-one relationship

2009-09-27 Thread triman
I have a model that can be attached to a variety of different models, based on the value of a column. Is there any way to map this relationship in Django? If not, is there a way to automatically do post-fetch processing where I could populate it? Here is a example: class Note(models.Model):

Re: Many to One Relationship

2008-08-27 Thread Daniel A.
Thanks, now is working fine. On 27 ago, 19:22, lingrlongr <[EMAIL PROTECTED]> wrote: > The error is generated because you have two fields in the Swap model > that refer to the User model, and two that refer to the Shifts model. > As the error states you need to specify the related_name value for

Re: Many to One Relationship

2008-08-27 Thread lingrlongr
The error is generated because you have two fields in the Swap model that refer to the User model, and two that refer to the Shifts model. As the error states you need to specify the related_name value for those ForeignKeys. Take a look at the documentation for related_name here:

Many to One Relationship

2008-08-27 Thread Daniel A.
Hi! I'm a switcher from Rails and I'm learning Django. I'm stuck with something I thing should be easy but for some reason I can't find the error. I'm trying to define a model to manage shifts for volunteers. I have three diferent models, Shifts, Users and Swaps. A User have many Shifts and a

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
I started composing a reply to your response, and then realized that I had erroneously constructed a mental one-to-one model of the relationship rather than one-to-many. You're absolutely right, what I was trying to do doesn't make any sense. Whoops :) Mike On May 13, 2:28 pm, "Scott

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, I think I understand what you're getting at, given your comment referring to the "unnecessary table and associated join". I think you want to be able to say "ManyToOneField" in Place and have it reach back into the Photo model and insert a NULLable "place_id" column. That's problematic

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Richard Dahl
A third alternative is to use a GenericForeignKey. Although this may add too much complexity. Put the GenericForeignKey in a model called PhotoTag and create a M2M relationship between it and Photo and use it to select either a Place or a UserProfile, i.e. class PhotoTag(models.Model)

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
Sure. OOM relationships can typically be broken down along two dimensions: cardinality and directionality. cardinality: DIRECTIONALITY -- One-to-one: ONE-WAY, BI-WAY One-to-many: ONE-WAY, BI-WAY Many-to-many: ONE-WAY, BI-WAY The cardinality

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, can you elaborate on what you mean by "forcing bi-directional relationships"? The ManyToManyField approach really is, I think, the "right" way to do it. If you think about it, a hypothetical ManyToOneField in your case would work almost exactly like the ManyToManyField. The join table

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
Thanks much, Scott. They both seem a bit hacky, but it gives me something to work with anyway. I recognize the motivation for forcing bi-directional relationships in Django was done to keep things DRY[1], but does anyone know if there's been any discussion about maybe relaxing this constraint?

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, you have two alternatives: 1. Create ManyToManyField fields in the UserProfile and Place models, pointing to Photo. "ManyToManyField" may seem a bit odd since you really have a many-to-one relation, but it will work as you expect, creating a join table connecting each pair

Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
I have some Places and I have some Users in my database. I'd like to be able to associate some Photos with each. class Photo(models.Model): # a model that represents a photo class UserProfile(models.Model): # has a list of Photos class Place(models.Model): # has a list of

Re: Simple many to one relationship queries

2007-06-13 Thread vhg119
Nevermind. I should have searched a little more. I found this which explains it all: http://www.djangoproject.com/documentation/db-api/#backward I can't wait for my Django programming book to be delivered. On Jun 13, 2:24 pm, vhg119 <[EMAIL PROTECTED]> wrote: > To clarify, is there a built in

Re: Simple many to one relationship queries

2007-06-13 Thread vhg119
To clarify, is there a built in way of doing manName = "ford" m = Manufacturer.objects.filter(name = manName)[0] c = m.list_of_cars() rather than doing another search and filter through Cars? On Jun 13, 2:20 pm, vhg119 <[EMAIL PROTECTED]> wrote: > Say I have these two models: > > class

Re: Creating a root object for a many-to-one relationship

2006-06-10 Thread arthur debert
won't this work for you: class Node(Model): parent = ForeignKey('self', blank=True, null=True) ... rest of your model... then fetch it like Node.objects.filter(parent__isnull=True) if you are worried with the possibility of ending up with mode that one root node you could do either