I want to build an application in which a patient uploads his report to his companion doctor ,
So , I have two models one for Doctors and other for patients.
What I want is to have a relationship between the two models , in which a patient chooses his doctor from the registered doctors.
this is the code:
class DoctorModel(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
doctorName = models.CharField(max_length = 150 , default="")
doctorEmail = models.EmailField(max_length=50, default="")
speciality = models.CharField(choices = SPECIALITY ,max_length = 20 , default="")
doctorStatus = models.CharField(choices = DOCTOR_STATUS ,max_length = 15 , default="")
class PatientModel(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
patientName = models.CharField(max_length = 150 , default="", editable=True)
patientAge = models.IntegerField(default=0)
patientEmail = models.EmailField(max_length=50, default="", editable=True)
insuranceSyndicate = models.CharField(choices = INSURANCE_SYNDICATE, max_length = 15, default="")
slug = models.SlugField(max_length = 50 , default= '')
referencedDoctor = models.ForeignKey(DoctorModel, on_delete=models.Set_Null)
What I want that when a patient choose the "referencedDoctor" , he choose him from "doctorName" in the DoctorModel
How can I do it ?
you should create __ str __ method to your models.
class DoctorModel(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
doctorName = models.CharField(max_length = 150 , default="")
doctorEmail = models.EmailField(max_length=50, default="")
speciality = models.CharField(choices = SPECIALITY ,max_length = 20 , default="")
doctorStatus = models.CharField(choices = DOCTOR_STATUS ,max_length = 15 , default="")
def __str__(self):
return f"{self.doctorName}"
BTW, try use null=True to your Fields. will be easier to implement.
You can define a dunder string function in the Doctor model like this
class DoctorModel(models.Model):
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
doctorName = models.CharField(max_length = 150 , default="")
doctorEmail = models.EmailField(max_length=50, default="")
speciality = models.CharField(choices = SPECIALITY ,max_length = 20 , default="")
doctorStatus = models.CharField(choices = DOCTOR_STATUS ,max_length = 15 , default="")
def__str__(self):
return self.doctorName
Related
I'm trying to create an app that meets two random users in Django.
my question is how to create an object Meeting out of 2 random users from my User model,
I want something like a for loop so that every 2 users in my database have a meeting!
ps: I have only one day left to submit my work I will be so thankful if u help me
this is my code so far:
def createMeeting():
user_p = get_user_model()
users = user_p.objects.all()
all_users = users.exclude(username="Admin")
n = all_users.count()
for k in range(math.floor(n/2)):
for user in all_users:
freedate = FreeDate.objects.filter(user=user)
starreds = user.userprofile.desired_user.all()
matched_user = User
if freedate:
if starreds:
for u in starreds:
u_freedate = FreeDate.objects.filter(user=u.user)
for dates in freedate:
for matchdates in u_freedate:
if dates.FreeTime == matchdates.FreeTime and dates.FreeDay == matchdates.FreeDay:
matched_user = u.user
else:
for u in users:
u_freedate = FreeDate.objects.filter(user = u)
for dates in freedate:
for matchdates in u_freedate:
if dates.FreeTime == matchdates.FreeTime and dates.FreeDay == matchdates.FreeDay:
matched_user = u
if matched_user and matched_user != user and not(Meeting.objects.filter(user1=user, user2=matched_user) | Meeting.objects.filter(user1=matched_user, user2=user)):
Meeting.objects.create(user1=user, user2=matched_user)`
it creates only one Meeting object and i'm getting this error:
TypeError: Field 'id' expected a number but got <class 'django.contrib.auth.models.User'>.
This is my models.py :
class UserProfile(models.Model):
GENDER=(
('Female','Female'),
('Male','Male'),
('Others', 'Others'),
)
user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
birthdate = models.DateTimeField(default=timezone.now, null=True)
phone = models.CharField(max_length=200, null=True)
age = models.IntegerField(null=True, default=18)
years_of_experience = models.IntegerField(null=True, default=5)
job_title = models.CharField(max_length=200, null=True)
gender = models.CharField(max_length=200, null=True, choices=GENDER)
profile_image = models.ImageField(null=True, blank=True)
about = models.TextField(null=True)
desired_user = models.ManyToManyField("self")
skill = models.ManyToManyField("Skill")
`class Meeting(models.Model):
STATE_CHOICES = [
('Accepte', 'Accepte'),
('Deny', 'Deny'),
]
RATE_MEETING = [
(1, '1'),
(2, '2'),
(3, '3'),
(4, '4'),
(5, '5'),
]
user1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user1', null=True)
user2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user2', null=True)
state1 = models.CharField(max_length=200, null=True, choices=STATE_CHOICES)
state2 = models.CharField(max_length=200, null=True, choices=STATE_CHOICES)
text1 = models.TextField(max_length=3000, null=True, blank=True)
text2 = models.TextField(max_length=3000, null=True, blank=True)
rate1 = models.PositiveSmallIntegerField(choices=RATE_MEETING, null=True, blank=True)
rate2 = models.PositiveSmallIntegerField(choices=RATE_MEETING, null=True, blank=True)
meeeting_place = models.ForeignKey(MeetingPlace, on_delete=models.CASCADE, null=True)`
I can't decipher what you're doing there, but:
for k in range(math.floor(n/2)):
for user in all_users:
freedate = FreeDate.objects.filter(user=user)
starreds = user.userprofile.desired_user.all()
matched_user = User # this is the line that's causing the error. Need an User instance, not the User class.
if freedate:
i have this order model:
class Order(models.Model):
productType = [
('Document', 'Document'),
('Parcel', 'Parcel'),
('Box', 'Box')
]
serviceType = [
('Home', 'Home delivery'),
('Office', 'Office delivery'),
('Pick up from office', 'Pick up from office'),
]
delivery_StatusType = [
('Return', 'Return'),
('Delivering', 'Delivering'),
('Pending', 'Pending'),
('Complete', 'Complete')
]
statustype = [
('Paid', 'Paid'),
('Cash on delivery', 'Cash on delivery')
]
status = [
('Instant', 'Instant'),
('Same Day', 'Same Day'),
('Others', 'Others')
]
payment_types = [
('Cash', 'Cash'),
('Wallet', 'Wallet'),
('Online', 'Online')
]
CHOICE_AREA = [
('Inside Dhaka', 'Inside Dhaka'),
('Dhaka Suburb', 'Dhaka Suburb'),
('Outside Dhaka', 'Outside Dhaka')
]
user = models.ForeignKey(User, on_delete=models.CASCADE)
receiver = models.CharField(max_length=100, blank=False, unique=False)
receiver_Contact = models.CharField(
max_length=20, blank=False, unique=False)
receiver_Email = models.CharField(
max_length=100, blank=False, unique=False)
payment = models.CharField(
max_length=100, choices=payment_types, blank=False)
area = models.CharField(
max_length=100, choices=CHOICE_AREA, blank=True, null=True)
weight = models.CharField(max_length=100, blank=True, null=True)
service = models.CharField(choices=serviceType, max_length=100)
product_Type = models.CharField(choices=productType, max_length=100)
contents = models.CharField(max_length=100, blank=False, unique=False)
quantity = models.CharField(max_length=100, blank=False, unique=False)
package = models.ForeignKey(
Package, on_delete=models.CASCADE, default=0)
priority = models.CharField(
choices=status, blank=True, null=True, max_length=20)
amount = models.CharField(max_length=100, blank=True, unique=False)
delivery_Status = models.CharField(
choices=delivery_StatusType, blank=True, null=True, max_length=50)
paid = models.BooleanField(default=False)
reference_id = models.CharField(max_length=100, blank=True, unique=True)
delivery_time = models.DateField(blank=True, null=True)
created = models.DateField(auto_now_add=True)
tran_id = models.CharField(max_length=20, blank=True, null=True)
driver = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='driver', blank=True, null=True)
driver_amount = models.CharField(max_length=5, blank=False, default='0')
delivery_now = models.DateField(auto_now_add=True)
delivery_later = models.DateField(blank=True, null=True)
accept = models.BooleanField(default=False)
start = models.BooleanField(blank=True, null=True)
finish = models.BooleanField(blank=True, null=True)
pick_up_latitude = models.CharField(blank=True, null=True, max_length=50)
pick_up_longitude = models.CharField(blank=True, null=True, max_length=50)
delivery_latitude = models.CharField(blank=True, null=True, max_length=50)
delivery_longitude = models.CharField(blank=True, null=True, max_length=50)
otp = models.CharField(max_length=10, blank=True, null=True)
pickup_finish = models.BooleanField(default=False)
approve_change_delivery_address = models.BooleanField(
blank=True, null=True, default=False)
confirm_change_delivery_address = models.BooleanField(
blank=True, null=True, default=False)
def __str__(self):
return self.user.username
user model:
class User(AbstractUser):
CITIES = [
('Dhaka','Dhaka'),
('Rajshahi','Rajshahi'),
('Chittagong','Chittagong'),
('Sylhet','Sylhet'),
('Khulna','Khulna'),
('Mymensingh','Mymensingh'),
('Rangpur','Rangpur'),
('Dinajpur','Dinajpur'),
]
Vehicle_type = [
('Truck','Truck'),
('Van','Van'),
('Bike','Bike')
]
email = models.EmailField(unique=True)
contact = models.CharField(null=False,blank=False,max_length=20)
contact2 = models.CharField(null=True,blank=True,max_length=20)
contact3 = models.CharField(null=True,blank=True,max_length=20)
contact4 = models.CharField(null=True,blank=True,max_length=20)
address = models.CharField(null=False,blank=False,max_length=100)
address2 = models.CharField(null=True,blank=True,max_length=100)
postal_code = models.CharField(null=True,blank=True,max_length=10)
city = models.CharField(max_length=30,choices=CITIES)
username = models.CharField(max_length=200,unique=True)
user_pic = models.ImageField(upload_to='media/images/')
n_id = models.CharField(max_length=100)
quote = models.CharField(max_length=250,blank=True,null=True,default='Bio Here. . .')
driving_license = models.ImageField(upload_to='media/documents/')
vehicle_type = models.CharField(max_length=30,choices=Vehicle_type)
vehicle_no = models.CharField(max_length=50)
latitude = models.CharField(max_length=100,default=0)
longitude = models.CharField(max_length=100,default=0)
is_driver = models.BooleanField(default=False)
is_delivery_man = models.BooleanField(default=False)
is_merchant = models.BooleanField(default=False)
is_agent = models.BooleanField(default=False)
is_user = models.BooleanField(default=False)
is_available = models.BooleanField(default=False)
def __str__(self):
return self.username
now the problem is i want to show the username , total amount collections and total orders by individual users(is_agent).no name will be repeated twice though the queryset can have multiple orders agains a user.
i just want to show a users orders total amount and total deliveries in a table row,then other row will be for other users. N.B.filtering (delivery_status="Complete")
update:
agents = User.objects.filter(is_active=True,is_agent=True)
for agent in agents:
agent_id = agent.id
all_orders = Order.objects.filter(user_id = agent_id, delivery_Status="Pending", delivery_time__month = date,
delivery_time__year = year)
now in here i want every agents total delivery count and total amount collected from them but not like showing same user's all querysets but instead i want only by his name will appear once in the table and all deliveries total amount and total deliveries into that row just like the given table
itried this but this has no track of which collection is for whom
individual_orders = []
final_list = []
grand_final_list = []
order_amount = []
individual_orders_count = []
agents = User.objects.filter(is_active=True,is_agent=True)
for agent in agents:
agent_id = agent.id
all_orders = Order.objects.filter(user_id = agent_id, delivery_Status="Pending", delivery_time__month = date,
delivery_time__year = year)
if all_orders:
individual_orders.append(all_orders)
individual_orders_count.append(len(all_orders))
cash_collection = Order.objects.filter(user_id = agent_id, delivery_Status="Pending", delivery_time__month = date,
delivery_time__year = year).values('amount').aggregate(Sum('amount'))
for k,v in cash_collection.items():
if v:
order_amount.append(v)
for query in individual_orders:
for entry in query:
final_list.append(entry.user.username)
grand_final_list = list(dict.fromkeys(final_list))
this table
maybe this helps you?
all_orders = Order.objects.filter(user_id = agent_id, delivery_Status="Pending", delivery_time__month = date,
delivery_time__year = year).values(id, username=F(user__username)).annotate(total_amount = Sum('amount')).annotate(total_deliveries = Count('id))
finally i found a way i am showing the demo here
def driver_deliveries(request):
name = {}
data = []
count = Order.objects.filter(driver__is_driver=True).distinct()
for i in count:
query = Order.objects.filter(driver_id=i.driver.id,delivery_Status="Complete").count()
name[i.driver.username] = data
data.append(query)
data = []
print(name)
for k,v in name.items():
print(k)
for i in v:
print(i)
return render(request,'user/driver_deliveries.html',{'name': name})
I don't understand why i'm getting this error when I try to insert the xlsx file. This is my model
class Finance(models.Model):
invoiceNumber = models.CharField(blank=False, null=False,
primary_key=True)
student = models.CharField(max_length=50, blank=False, null=False)
rollGroup = models.CharField(max_length=50, blank=False, null=False)
invoiceTo = models.CharField(max_length=50, blank=False, null=False)
dob = models.CharField(max_length=50, null=True)
gender = models.CharField(max_length=50, blank=False, null=False)
status = models.CharField(max_length=50, blank=False, null=False)
schedule = models.CharField(max_length=50,blank=False, null=False)
totalValue = models.CharField(max_length=50, blank=False, null=False)
issueDate = models.CharField(max_length=50, null=True)
dueDate = models.CharField(max_length=50, null=True)
datePaid = models.CharField(max_length=50, null=True)
amountPaid = models.CharField(max_length=50, null=True)
def __str__(self):
return self.invoiceNumber
This is my resource model
class FinanceResource(resources.ModelResource):
invoiceNumber = Field(attribute='invoiceNumber', column_name='Invoice
Number')
student = Field(attribute='student', column_name='Student')
rollGroup = Field(attribute='rollGroup', column_name='Roll Group')
invoiceTo = Field(attribute='invoiceTo', column_name='Invoice To')
dob = Field(attribute='dob', column_name='DOB')
gender = Field(attribute='gender', column_name='Gender')
status = Field(attribute='status', column_name='Status')
schedule = Field(attribute='schedule', column_name='Schedule')
totalValue = Field(attribute='totalValue', column_name='Total
Value(PKR
₨)')
issueDate = Field(attribute='issueDate', column_name='Issue Date')
dueDate = Field(attribute='dueDate', column_name='Due Date')
datePaid = Field(attribute='datePaid', column_name='Date Paid')
amountPaid = Field(attribute='amountPaid', column_name='Amount Paid
(PKR
₨)')
class Meta:
model = Finance
import_id_fields = ('invoiceNumber',)
export_order = ('invoiceNumber', 'student', 'rollGroup',
'invoiceTo', 'dob', 'gender', 'status', 'schedule',
'totalValue', 'issueDate', 'dueDate', 'datePaid',
'amountPaid')
skip_unchanged = True
report_skipped = True
And the error im getting
And when i use the default primary key i get
Line number: 1 - str returned non-string (type int)
2, styles, harry, Spring 2020, Family, None, M, Pending, First Installment, 57000, None, 10/06/2020, None, 0
Traceback (most recent call last):
File "C:\Users\long play computers\PycharmProjects\DotsPrototype\venv\lib\site-packages\import_export\resources.py", line 559, in import_row
row_result.object_repr = force_str(instance)
File "C:\Users\long play computers\PycharmProjects\DotsPrototype\venv\lib\site-packages\django\utils\encoding.py", line 64, in force_str
s = str(s)
TypeError: str returned non-string (type int)
I have following model
class Day(models.Model):
date = models.DateField(auto_now=False, auto_now_add=False)
price = models.FloatField()
payment_method = models.CharField(max_length = 200, blank=True)
payment_date = models.CharField(max_length=200, blank=True)
room = models.ForeignKey(Room, null=True, blank=True, verbose_name='Номер', on_delete=models.CASCADE)
def __unicode__(self):
return str(self.date)
class Reservation(models.Model):
start = models.DateField(verbose_name='Заезд', auto_now=False, auto_now_add=False, blank=False)
end = models.DateField(verbose_name='Выезд', auto_now=False, auto_now_add=False, blank=False)
check_in_time = models.TimeField(verbose_name='Время заезда', blank=False)
check_out_time = models.TimeField(verbose_name='Время выезда', blank=False)
has_refund = models.BooleanField(verbose_name='Возвратная бронь', default=True)
payed = models.BooleanField(verbose_name='Оплачено', default=False)
reserved_days = models.ManyToManyField(Day, blank=False)
additional_services = models.ManyToManyField(AdditionalService)
guest_name = models.CharField(verbose_name='Имя гостя', max_length=200, blank=True)
reservation_number = models.CharField(verbose_name='Номер брони', max_length=200, blank=True)
What I want is to have ability to edit Day on Reservation page
I try the following as in the django docs
class ReservedDaysInline(admin.TabularInline):
model = Reservation
extra = 1
class ReservationAdmin(admin.ModelAdmin):
inlines = (ReservedDaysInline,)
class DayAdmin(admin.ModelAdmin):
inline = (ReservedDaysInline,)
admin.site.register(Reservation, ReservationAdmin)
admin.site.register(Day, DayAdmin)
But it doesnt work.
What am I doing wrong ?
Try this from doc
class ReservedDaysInline(admin.TabularInline):
model = Reservation.reserved_days.through
extra = 1
class ReservationAdmin(admin.ModelAdmin):
inlines = (ReservedDaysInline,)
exclude = ('reserved_days',)
I am attempting to use the Django prefetch_related because of the 1 to many relationship between models LanguageCode and Flag shown below (I am attempting to display the flagIconPath), but I cannot seem to get the views.py code correct and I really need some help!
Here is my views.py form:
from django.shortcuts import render
from app_data.models import RIAchievement
def ri_achievements(request):
qs = RIAchievement.objects.all().prefetch_related("??????", "????????")
return render(request, 'index.html',{'qs': qs})
What code should I be using to replace the ???'s?
Here are the fields I am trying to get the django prefetch_related to display:
(flag) flagiconpath,
(riachievement) riAchievementTypeUserDescription,
(typeachievement) typeAchievementDescriptionIntl,
(languagecode) languageNameNative,
(flag) flagIconPath,
(languagedetail) languageDetailDescription,
(languagedirection) languageDirectionDescription,
(riusersettings) riUserSettingsDisplayMultipleLanguage,
(typeresumestyle) typeResumeStyleNumber,
(auth_user) id.
Here are my relevant models:
class RIAchievement(models.Model):
riAchievementID = models.AutoField(primary_key=True, db_column="riAchievementID")
userLanguageVersionID = models.ForeignKey(UserLanguageVersion, db_column="userLanguageVersionID", related_name="riAchievement_userLanguageVersionID")
typeAchievementID = models.ForeignKey(TypeAchievement, db_column="typeAchievementID", related_name="riAchievement_typeAchievementID")
riAchievementTypeUserDescription = models.CharField(max_length=255, blank=True, null=True, db_column="riAchievementTypeUserDescription")
riAchievementDescription = models.TextField(max_length=2000, db_column="riAchievementDescription")
auth_user_id = models.ForeignKey(auth_user, db_column="auth_user_id", related_name="riAchievement_auth_user_id")
class Meta:
db_table="riAchievement"
class TypeAchievement(models.Model):
typeAchievementID = models.AutoField(primary_key=True, db_column="typeAchievementID")
languageCodeID = models.ForeignKey(LanguageCode, db_column="languageCodeID", related_name="typeAchievement_languageCodeID")
typeAchievementDescriptionIntl = models.CharField(max_length=255, db_column="typeAchievementDescriptionIntl")
typeAchievementDescriptionEng = models.CharField(max_length=255, db_column="typeAchievementDescriptionEng")
typeAchievementAltID = models.IntegerField(db_column="typeAchievementAltID")
class Meta:
db_table="typeAchievement"
class UserLanguageVersion(models.Model):
userLanguageVersionID = models.AutoField(primary_key=True, db_column="userLanguageVersionID")
auth_user_id = models.ForeignKey(auth_user, db_column="auth_user_id", related_name="userLanguageVersion_auth_user_id")
languageCodeID = models.ForeignKey(LanguageCode, db_column="languageCodeID", related_name="userLanguageVersion_languageCodeID")
class Meta:
db_table="userLanguageVersion"
class LanguageCode(models.Model):
languagecodeID = models.AutoField(primary_key=True, db_column="languageCodeID")
languageCodeDescription = models.CharField(max_length=10, db_column="languageCodeDescription")
baseLanguageCode = models.CharField(max_length=10, db_column="baseLanguageCode")
languageNameEng = models.CharField(max_length=255, db_column="languageNameEng")
altLanguageNameEng = models.CharField(max_length=255, blank=True, null=True, db_column="altLanguageNameEng")
languageNameNative = models.CharField(max_length=255, db_column="languageNameNative")
altLanguageNameNative = models.CharField(max_length=255, blank=True, null=True, db_column="altLanguageNameNative")
iso639_1 = models.CharField(max_length=10, blank=True, null=True, db_column="iso639_1")
iso639_2T = models.CharField(max_length=10, db_column="iso639_2T")
iso639_2B = models.CharField(max_length=10, db_column="iso639_2B")
iso639_X = models.CharField(max_length=10, db_column="iso639_X")
languageDirectionID = models.ForeignKey(LanguageDirection, default=1, db_column="languageDirectionID", related_name="languageCode_languageDirectionID")
class Meta:
db_table="languageCode"
class Flag(models.Model):
flagID = models.AutoField(primary_key=True, db_column="flagID")
languageCodeID = models.ForeignKey(LanguageCode, db_column="languageCodeID", related_name="flag_languageCodeID")
flagIconPath = models.CharField(max_length=255, db_column="flagIconPath")
flagDescription = models.CharField(max_length=255, db_column="flagDescription")
flagInformation = models.CharField(max_length=255, db_column="flagInformation")
class Meta:
db_table="flag"
class auth_user(models.Model):
auth_user_id = models.AutoField(primary_key=True, db_column="id")
username = models.CharField(max_length=30, unique=True, db_column="username")
first_name = models.CharField(max_length=30, db_column="first_name")
last_name = models.CharField(max_length=30, db_column="last_name")
email = models.CharField(max_length=75, db_column="email")
password = models.CharField(max_length=128, db_column="password")
is_staff = models.BooleanField(db_column="is_staff")
is_active = models.BooleanField(db_column="is_active")
is_supervisor = models.BooleanField(db_column="is_supervisor")
last_login = models.DateTimeField(db_column="last_login")
date_joined = models.DateTimeField(db_column="date_joined")
class Meta:
db_table="auth_user"
class RIUserSettings(models.Model):
riUserSettingsID = models.AutoField(primary_key=True, unique=True, db_column="riUserSettingsID")
riUserSettingsPrimaryLanguageCodeID = models.ForeignKey(LanguageCode, db_column="riUserSettingsPrimaryLanguageCodeID", related_name="riUserSettings_riUserSettingsPrimaryLanguageCodeID")
riUserSettingsDisplayPrimaryLanguage = models.BooleanField(default=False, db_column="riUserSettingsDisplayPrimaryLanguage")
riUserSettingsDisplayMutipleLanguage = models.BooleanField(default=False, db_column="riUserSettingsDisplayMutipleLanguage")
riUserSettingsDisplaySingleLanguage = models.BooleanField(default=False, db_column="riUserSettingsDisplaySingleLanguage")
riUserSettingsPrimaryVirtualKeyboardLanguageVersionID = models.ForeignKey(UserLanguageVersion, db_column="riUserSettingsPrimaryVirtualKeyboardLanguageVersionID", related_name="riUserSettings_riUserSettingsPrimaryVirtualKeyboardLanguageVersionID")
riUserSettingsDisplayPrimaryVirtualKeyboard = models.BooleanField(default=False, db_column="riUserSettingsDisplayPrimaryVirtualKeyboard")
riUserSettingsDisplayRIFormattingPreview = models.BooleanField(default=True, db_column="riUserSettingsDisplayRIFormattingPreview")
typeResumeStyleID = models.ForeignKey(TypeResumeStyle, db_column="typeResumeStyleID", related_name="riUserSettings_typeResumeStyleID")
auth_user_id = models.ForeignKey(auth_user, db_column="auth_user_id", related_name="riUserSettings_auth_user_id")
class Meta:
db_table="riUserSettings"
class LanguageDetail(models.Model):
languageDetailID = models.AutoField(primary_key=True, unique=True, db_column="languageDetailID")
languageCodeID = models.ForeignKey(LanguageCode, db_column="languageCodeID", related_name="languageDetail_languageCodeID")
nativeLanguageCodeID = models.ForeignKey(LanguageCode, db_column="nativeLanguageCodeID", related_name="languageDetail_nativeLanguageCodeID")
languageDetailDescriptionIntl = models.CharField(max_length=255, db_column="languageDetailDescriptionIntl")
languageDetailDescriptionEng = models.CharField(max_length=255, db_column="languageDetailDescriptionEng")
languageDetailDescriptionNative = models.CharField(max_length=255, db_column="languageDetailDescriptionNative")
displayCapitaliseCountryName = models.BooleanField(default=False, db_column="displayCapitaliseCountryName")
languageDirectionID = models.ForeignKey(LanguageDirection, default=1, db_column="languageDirectionID", related_name="languageDetail_languageDirectionID")
flagID = models.ForeignKey(Flag, db_column="flagID", related_name="languageDetail_FlagID")
languageDetailAltID = models.IntegerField(db_column="languageDetailAltID")
class Meta:
db_table="languageDetail"
class LanguageDirection(models.Model):
languageDirectionID = models.AutoField(primary_key=True, db_column="languageDirectionID")
languageDirectionDescription = models.CharField(max_length=20, db_column="languageDirectionDescription")
languageDirDescription = models.CharField(max_length=20, db_column="languageDirDescription")
textAlign = models.CharField(max_length=20, db_column="textAlign")
oppositeLanguageDirectionDescription = models.CharField(max_length=20, db_column="oppositeLanguageDirectionDescription")
oppositeLanguageDirDescription = models.CharField(max_length=20, db_column="oppositeLanguageDirDescription")
oppositeTextAlign = models.CharField(max_length=20, db_column="oppositeTextAlign")
class Meta:
db_table="languageDirection"
class TypeResumeStyle(models.Model):
typeResumeStyleID = models.AutoField(primary_key=True, db_column="typeResumeStyleID")
languageCodeID = models.ForeignKey(LanguageCode, db_column="languageCodeID", related_name="typeResumeStyle_languageCodeID")
typeResumeStyleNumber = models.IntegerField(db_column="typeResumeStyleNumber")
typeResumeStyleNameIntl = models.CharField(max_length=255, db_column="typeResumeStyleNameIntl")
typeResumeStyleNameEng = models.CharField(max_length=255, db_column="typeResumeStyleNameEng")
typeResumeStyleDescriptionIntl = models.CharField(max_length=255, db_column="typeResumeStyleDescriptionIntl")
typeResumeStyleDescriptionEng = models.CharField(max_length=255, db_column="typeResumeStyleDescriptionEng")
class Meta:
db_table="typeResumeStyle"
Aagh, my eyes. Please give your fields suitably Pythonic names. Especially since you're already using the db_column attribute, you can keep your DB as it is and give your fields names we can actually read.
In particular, your ForeignKey fields shouldn't be called fooId: the underlying database field is an ID, but the field is not, it's a reference to the actual FK model.
To answer your question though, all the FKs you mention are forward references, not backwards. So you need to use select_related, not prefetch_related, here.