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
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
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
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)
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)
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.
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
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):
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
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:
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
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
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
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)
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
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
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?
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
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
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
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
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
22 matches
Mail list logo