Ich habe drei Modelle Universitäten, Benutzertyp und Benutzer.Universitätsmodell enthalten Liste aller Universität und Benutzer-Typ enthalten zwei Arten von Benutzertyp Fakultät und Student und Benutzermodell enthält alle Benutzer.Wie findet man Kreuzung von Django-Modellen?
Nun, was ich erreichen möchte, ist, alle Benutzer zu bekommen, die den Kreuzungen der Universität des Benutzertyps gehören. Angenommen, ich wählte abc Universität und Benutzer Typ Fakultät dann wie bekomme ich alle Benutzer von dieser abc Universität mit Fakultät Typ.
Kann meine Modelle helfen, besser zu verstehen: -
Universitätsmodell: -
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
# WE ARE AT MODELS/UNIVERSITIES
class Universities(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
name = models.CharField(db_column="name", max_length=255, help_text="")
abbreviation = models.CharField(db_column="abbreviation", max_length=255, help_text="")
address = models.CharField(db_column="address", max_length=255, help_text="")
status = models.BooleanField(db_column="status", default=False, help_text="")
createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")
modifiedAt = models.DateTimeField(db_column='modifiedAt', auto_now=True, help_text="")
updatedBy = models.ForeignKey(User,db_column="updatedBy",help_text="Logged in user updated by ......")
class Meta:
managed = False
get_latest_by = 'createdAt'
db_table = 'universities'
mein Benutzertyp Modell: -
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
# WE ARE AT MODELS/MASTER USERS TYPES
class MasterUserTypes(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
userType = models.CharField(db_column='userType', max_length=255, help_text="")
description = models.CharField(db_column='desciption', max_length=255, help_text="")
status = models.BooleanField(db_column="status", default=False, help_text="")
createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")
modifiedAt = models.DateTimeField(db_column='modifiedAt', auto_now=True, help_text="")
updatedBy = models.ForeignKey(User, db_column='updatedBy',
help_text="Logged in user updated by ......")
class Meta:
managed = False
db_table = 'master_user_types'
und Benutzer-Modelle: -
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from cms.models.masterUserTypes import MasterUserTypes
from cms.models.universities import Universities
from cms.models.departments import MasterDepartments
# WE ARE AT MODELS/APPUSERS
requestChoice = (
('male', 'male'),
('female', 'female'),
)
class Users(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
userTypeId = models.ForeignKey(MasterUserTypes, db_column="userTypeId")
universityId = models.ForeignKey(Universities, db_column="universityId")
departmentId = models.ForeignKey(MasterDepartments , db_column="departmentId",help_text="")
name = models.CharField(db_column="name",max_length=255,help_text="")
username = models.CharField(db_column="username",unique=True, max_length=255,help_text="")
email = models.CharField(db_column="email",unique=True, max_length=255,help_text="")
password = models.CharField(db_column="password",max_length=255,help_text="")
bio = models.TextField(db_column="bio",max_length=500,help_text="")
gender = models.CharField(db_column="gender",max_length=6, choices=requestChoice,help_text="")
mobileNo = models.CharField(db_column='mobileNo', max_length=16,help_text="")
dob = models.DateField(db_column="dob",help_text="")
major = models.CharField(db_column="major",max_length=255,help_text="")
graduationYear = models.IntegerField(db_column='graduationYear',max_length=11,help_text="")
canAddNews = models.BooleanField(db_column='canAddNews',default=False,help_text="")
receivePrivateMsgNotification = models.BooleanField(db_column='receivePrivateMsgNotification',default=True ,help_text="")
receivePrivateMsg = models.BooleanField(db_column='receivePrivateMsg',default=True ,help_text="")
receiveCommentNotification = models.BooleanField(db_column='receiveCommentNotification',default=True ,help_text="")
receiveLikeNotification = models.BooleanField(db_column='receiveLikeNotification',default=True ,help_text="")
receiveFavoriteFollowNotification = models.BooleanField(db_column='receiveFavoriteFollowNotification',default=True ,help_text="")
receiveNewPostNotification = models.BooleanField(db_column='receiveNewPostNotification',default=True ,help_text="")
allowInPopularList = models.BooleanField(db_column='allowInPopularList',default=True ,help_text="")
xmppResponse = models.TextField(db_column='xmppResponse',help_text="")
xmppDatetime = models.DateTimeField(db_column='xmppDatetime', help_text="")
status = models.BooleanField(db_column="status", default=False, help_text="")
createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")
modifiedAt = models.DateTimeField(db_column='modifiedAt', auto_now=True, help_text="")
updatedBy = models.ForeignKey(User,db_column="updatedBy",help_text="Logged in user updated by ......")
lastPasswordReset = models.DateTimeField(db_column='lastPasswordReset',help_text="")
authorities = models.CharField(db_column="departmentId",max_length=255,help_text="")
class Meta:
managed = False
db_table = 'users'
so ho W kann ich die Kreuzung finden .... entschuldigen Sie mich, wenn Sie irgendwelche Fehler finden. Thansk im Voraus
wenn Benutzer mir den Namen Personal Tye und Universität sagen, dann will ich alle Benutzer, die –
der Universität und des spezifischen Personal Typ gehört ja die obige Abfrage wird Ihnen helfen mit dem, was du erreichen willst. überprüfen Sie und lassen Sie mich wissen, wenn das Ergebnis für Sie nicht wünschenswert ist. cheers – Exprator
das funktionierte ich war multiple Wert von Universität und usertype so verwendet ich usertype_id__in.thanks –