reset id whenever a row deleted in django - django

i wanted to start id from 1 .
whenever a row deleted it skips that number and jump to next number.
like in this image it skips number from 1-6 and 8.
i want to set it as 1,2,3
this is my models.py
class dish(models.Model):
id = models.AutoField(primary_key=True)
dish_id = models.AutoField
dish_name = models.CharField(max_length=255, blank=True, null=True)
dish_category = models.CharField(max_length=255, blank=True, null=True)
dish_size = models.CharField(max_length=7, blank=True, null=True)
dish_price = models.IntegerField(blank=True, null=True)
dish_description = models.CharField(max_length=255, blank=True, null=True)
# dish_image = models.ImageField(upload_to="images/", default=None, blank=True, null=True)
dish_image = models.ImageField(upload_to="media/", default=None, blank=True, null=True) #here added images as a foldername to upload to.
dish_date = models.DateField()
def __str__(self):
return self.dish_name
this is views.py
def delete(request, id):
dishs = dish.objects.get(id=id)
dishs.delete()
return HttpResponseRedirect(reverse('check'))

Related

how to reset id whenever a row deleted in django?

I wanted to start id from 1 whenever a row is deleted it skips that number and jumps to the following number.
like in this image it skips numbers from 1-6 and 8.
I want to set it as 1,2,3.
Here is my models.py module
class dish(models.Model):
id = models.AutoField(primary_key=True)
dish_id = models.AutoField
dish_name = models.CharField(max_length=255, blank=True, null=True)
dish_category = models.CharField(max_length=255, blank=True, null=True)
dish_size = models.CharField(max_length=7, blank=True, null=True)
dish_price = models.IntegerField(blank=True, null=True)
dish_description = models.CharField(max_length=255, blank=True, null=True)
# dish_image = models.ImageField(upload_to="images/", default=None, blank=True, null=True)
dish_image = models.ImageField(upload_to="media/", default=None, blank=True, null=True) #here added images as a foldername to upload to.
dish_date = models.DateField()
def __str__(self):
return self.dish_name
Here is views.py module:
def delete(request, id):
dishs = dish.objects.get(id=id)
dishs.delete()
return HttpResponseRedirect(reverse('check'))
Deleting an object does not change any property of the remaining objects. You need to do that manually. First thing you need to do is to change the dish_id field:
# Change this:
# dish_id = models.AutoField
# to this:
dish_id = models.IntegerField(default=0)
Then in your views:
def delete(request, id):
dishs = dish.objects.get(id=id)
dishs.delete()
all_dishes = dish.objects.all()
for i, dish in enumerate(all_dishes):
dish.dish_id = i + 1
dish.save()
return HttpResponseRedirect(reverse('check'))
Separately, you really should write your classes in Pascal case, capitalizing the first letter of the class:
class Dish(models.Model):
And finally, Dish does not need an id field; that is created automatically, but you can leave that as is, it is not causing any problems.
You can achieve those things using an overriding save() method like this
class dish(models.Model):
id =models.AutoField(primary_key=True)
dish_id = models.BigIntegerField(unique = True)
dish_name = models.CharField(max_length=255, blank=True, null=True)
dish_category = models.CharField(max_length=255, blank=True, null=True)
dish_size = models.CharField(max_length=7, blank=True, null=True)
dish_price = models.IntegerField(blank=True, null=True)
dish_description = models.CharField(max_length=255, blank=True, null=True)
dish_image = models.ImageField(upload_to="images/", default=None, blank=True, null=True)
dish_image = models.ImageField(upload_to="media/", default=None, blank=True, null=True) #here added images as a foldername to upload to.
dish_date = models.DateField()
def __str__(self):
return self.dish_name
def save(self, *args, **kwargs):
count_obj = dish.objects.all().count()+1
self.dish_id = count_obj
super(dish, self).save(*args, **kwargs)

Build Inline Formsets in Django Admin

So I am new to Django and I have been reading a lot of documentation to figure this out, I have a table called "Logs" that has logs of different positions (has FK of table "Position"), each position belongs to a department (has FK to table "Department") Check the image below :1
What I want to do is create a view just like this one :
2
and whenever you click on a department, it extends all the positions in it with their respective logs like this :
3
The Screenshots I have attached are my work in main app (or if you would like to call it front end), I wanted to replicate the same process in the Django Admin page, I keep seeing that I should use inlines but I can't seem to make it work, can someone help or put me in the right direction please ? much appreciated.
Here is what I have in my models.py :
from django.db import models
from django.contrib.auth.models import User
from PIL import Image
class Site(models.Model):
site = models.CharField(max_length=200, blank=True, null=True)
totalHC = models.IntegerField(blank=True, null=True)
def __str__(self):
return self.site
class Department(models.Model):
department = models.CharField(max_length=200, blank=True)
def __str__(self):
return self.department
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
site = models.ForeignKey(Site, on_delete=models.CASCADE, null=True, default=Site(id="1").site)
department = models.ForeignKey(
"Department", on_delete=models.CASCADE, null=True)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')
bio = models.CharField(max_length=2000, blank=True)
skills = models.CharField(max_length=2000, blank=True)
aoi = models.CharField(max_length=2000, blank=True)
github = models.CharField(max_length=200, blank=True)
linkedin = models.CharField(max_length=200, blank=True)
def __str__(self):
return f'{self.user.username} Profile'
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
img = Image.open(self.image.path)
if img.height > 300 or img.width > 300:
output_size = (300, 300)
img.thumbnail(output_size)
img.save(self.image.path)
class Grade(models.Model):
user = models.OneToOneField(Profile, on_delete=models.CASCADE)
ut1 = models.CharField(max_length=200, blank=True)
ut2 = models.CharField(max_length=200, blank=True)
ut3 = models.CharField(max_length=200, blank=True)
ut1p = models.ImageField(upload_to='plots', blank=True)
ut2p = models.ImageField(upload_to='plots', blank=True)
ut3p = models.ImageField(upload_to='plots', blank=True)
ut1pb = models.ImageField(upload_to='plots', blank=True)
ut2pb = models.ImageField(upload_to='plots', blank=True)
ut3pb = models.ImageField(upload_to='plots', blank=True)
ut12 = models.ImageField(upload_to='plots', blank=True)
ut13 = models.ImageField(upload_to='plots', blank=True)
ut23 = models.ImageField(upload_to='plots', blank=True)
class Section(models.Model):
class Meta:
verbose_name = 'Department'
verbose_name_plural = 'Departments'
section = models.CharField(max_length=200, blank=True)
def __str__(self):
return self.section
class Question(models.Model):
class Meta:
verbose_name = 'Position'
verbose_name_plural = 'Positions'
section = models.ForeignKey(
"Section", on_delete=models.CASCADE, null=True, blank=True)
question_field = models.CharField(max_length=2000, blank=True, null=True)
def __str__(self):
return self.question_field
class Answer(models.Model):
class Meta:
verbose_name = 'Log'
verbose_name_plural = 'Logs'
question = models.ForeignKey(Question, on_delete=models.CASCADE)
user = models.ForeignKey(Profile, on_delete=models.CASCADE)
answer_field = models.CharField(max_length=2000, blank=True, null=True)
def __str__(self):
return f"{self.user} answered {self.answer_field}"
class Position1(models.Model):
class Meta:
verbose_name = 'Position'
verbose_name_plural = 'Positions'
department = models.ForeignKey(
"Department", on_delete=models.CASCADE, null=True, blank=True)
position = models.CharField(max_length=200, blank=True)
jobID = models.CharField(max_length=200, blank=True)
class HCtype(models.TextChoices):
Staff = 'Staff', ('Staff')
IDL = 'IDL', ('IDL')
DL = 'DL', ('DL')
hctype = models.CharField(
max_length=5,
choices=HCtype.choices,
)
def __str__(self):
return self.position
class Log(models.Model):
position = models.ForeignKey(Position1, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
INN = models.IntegerField(blank=True, null=True)
OUT = models.IntegerField(blank=True, null=True)
date = models.CharField(max_length=200, blank=True)
internal = models.IntegerField(default=0, null=True)
class SiteHasPosition(models.Model):
date = models.CharField(max_length=200, blank=True)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
position = models.ForeignKey(Position1, on_delete=models.CASCADE)
value = models.IntegerField(blank=True, null=True)
standard = models.IntegerField(blank=True, null=True)
turn_over = models.IntegerField(blank=True, null=True)
class SiteHasDepartment(models.Model):
date = models.CharField(max_length=200, blank=True)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
department = models.ForeignKey(Department, on_delete=models.CASCADE)
value = models.IntegerField(blank=True, null=True)
class SiteKPIs(models.Model):
site = models.ForeignKey(Site, on_delete=models.CASCADE)
date = models.CharField(max_length=200, blank=True)
staff = models.IntegerField(blank=True, null=True)
dl = models.IntegerField(blank=True, null=True)
idl = models.IntegerField(blank=True, null=True)
total_hc = models.IntegerField(blank=True, null=True)
total_in = models.IntegerField(blank=True, null=True)
total_out = models.IntegerField(blank=True, null=True)
staff_rate = models.IntegerField(blank=True, null=True)
dl_rate = models.IntegerField(blank=True, null=True)
idl_rate = models.IntegerField(blank=True, null=True)
Here is how I registred them in admin.py :
admin.site.register(Profile)
admin.site.register(Log)
admin.site.register(Position1)
admin.site.register(Department)
admin.site.register(Site)
admin.site.register(SiteHasDepartment)
admin.site.register(SiteHasPosition)
I would like to have a page in admin.py where I can select a site and for that specific site display :
all the departments(when you press a dpt all the positions will expand) for each position the standardHC, attributes from the Log table (that match that position,and that site) and attributes from SiteHasPosition( that match the site and that position)
I hope I made it clearer

Django - error message: IndentationError: unindent does not match any outer indentation level

enter image description here
I'm having trouble solving this portion of my code.
This is the model.py inside my app.
The "image = models.ImageField(null=True, blank=True)" keeps giving me an error. I install Pillow library but didn't solve the problem
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Customer(models.Model):
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=True)
email = models.CharField(max_length=200, null=True)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=200, null=True)
price = models.FloatField()
digital = models.BooleanField(default=False,null=True, blank=False)
image = models.ImageField(null=True, blank=True)
def __str__(self):
return self.name
class Order(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True)
date_ordered = models.DateTimeField(auto_now_add=True)
complete = models.BooleanField(default=False)
transaction_id = models.CharField(max_length=100, null=True, blank=False)
def __str__(self):
return str(self.id)
class OrderItem(models.Model):
product = models.ForeignKey(Product, on_delete=models.SET_NULL, blank=True, null=True)
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
quantity = models.IntegerField(default=0, blank=True, null=True)
date_added = models.DateTimeField(auto_now_add=True)
class ShippingAddress(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True)
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
address = models.CharField(max_length=200, null=True)
city = models.CharField(max_length=200, null=True)
state = models.CharField(max_length=200, null=True)
zipcode = models.CharField(max_length=200, null=True)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.address
This type of error could mean that you have mixed spaces and tabs in you indentation, or other whitespace issues.
Is the line below it (line 19) empty or does in have some whitespace?

How to select specific tables from related tables(Django)?

I have a query that links five tables. In some of them I need one (name from contractor) field. Therefore, I want to optimize this and select only one field), and not the entire table. How can I edit this code?
paymentsss = Transaction.objects.all().select_related('currency',
'payment_source__payment_type', 'deal__service','deal__service__contractor')
Turns into
SELECT "processing"."transaction"."id",
"processing"."transaction"."currency_id",
"processing"."transaction"."deal_id",
"processing"."transaction"."service_instance_id",
"processing"."transaction"."payment_source_id",
"processing"."transaction"."payment_date",
"processing"."transaction"."amount",
"processing"."transaction"."status",
"processing"."transaction"."context",
"processing"."currency"."id",
"processing"."currency"."name",
"processing"."currency"."iso_name",
"processing"."currency"."minor_unit",
"processing"."deal"."id",
"processing"."deal"."service_id",
"processing"."deal"."currency_id",
"processing"."deal"."adapter_account_id",
"processing"."deal"."amounts_rule",
"processing"."deal"."comission_rule",
"processing"."deal"."weight_rule",
"processing"."deal"."active",
"processing"."deal"."provider_enabled",
"processing"."deal"."min_amount",
"processing"."deal"."max_amount",
"processing"."deal"."payment_types",
"processing"."deal"."params",
"processing"."deal"."contractor_params",
"processing"."deal"."tags",
"processing"."service"."id",
"processing"."service"."flow_id",
"processing"."service"."currency_id",
"processing"."service"."contractor_id",
"processing"."service"."amount",
"processing"."service"."callback_url",
"processing"."service"."definition",
"processing"."service"."name",
"processing"."service"."description",
"processing"."service"."charge_strategy",
"processing"."service"."routine",
"processing"."service"."tags",
"processing"."contractor"."id",
"processing"."contractor"."name",
"processing"."contractor"."inn",
"processing"."contractor"."kpp",
"processing"."contractor"."bank_reg_id",
"processing"."contractor"."bank_reg_date",
"processing"."contractor"."slug",
"processing"."contractor"."uuid",
"processing"."contractor"."is_nds_payer",
"processing"."contractor"."tag",
"processing"."payer_payment_source"."id",
"processing"."payer_payment_source"."payer_id",
"processing"."payer_payment_source"."payment_type_id",
"processing"."payer_payment_source"."source_details",
"processing"."payment_type"."id",
"processing"."payment_type"."name",
"processing"."payment_type"."group_name"
FROM "processing"."transaction"
LEFT OUTER JOIN "processing"."currency"
ON ("processing"."transaction"."currency_id" = "processing"."currency"."id")
LEFT OUTER JOIN "processing"."deal"
ON ("processing"."transaction"."deal_id" = "processing"."deal"."id")
LEFT OUTER JOIN "processing"."service"
ON ("processing"."deal"."service_id" = "processing"."service"."id")
LEFT OUTER JOIN "processing"."contractor"
ON ("processing"."service"."contractor_id" = "processing"."contractor"."id")
LEFT OUTER JOIN "processing"."payer_payment_source"
ON ("processing"."transaction"."payment_source_id" = "processing"."payer_payment_source"."id")
LEFT OUTER JOIN "processing"."payment_type"
ON ("processing"."payer_payment_source"."payment_type_id" = "processing"."payment_type"."id")
ORDER BY "processing"."transaction"."id" DESC
What i want to delete
I highlighted in red those columns that I wanted to delete.
Some of models from models.py
class Contractors(models.Model):
id = models.IntegerField(blank=True, null=False, primary_key=True)
name = models.CharField(max_length=255, blank=True, null=True)
inn = models.CharField(max_length=14, blank=True, null=True)
kpp = models.CharField(max_length=14, blank=True, null=True)
bank_reg_id = models.CharField(max_length=255, blank=True, null=True)
bank_reg_date = models.DateField(blank=True, null=True)
slug = models.CharField(max_length=255, blank=True, null=True)
uuid = models.CharField(max_length=36, blank=True, null=True)
is_nds_payer = models.BooleanField(blank=True, null=True)
tag = models.TextField(blank=True, null=True) # This field type is a guess.
class Meta:
managed = False
db_table = '"processing"."contractor"'
class PaymentType(models.Model):
id = models.CharField(max_length=75, blank=True, null=False, primary_key=True)
name = models.CharField(max_length=128, blank=True, null=True)
group_name = models.CharField(max_length=64, blank=True, null=True)
class Meta:
managed = False
db_table = '"processing"."payment_type"'
class Service(models.Model):
id = models.IntegerField(db_index=True, blank=True, null=False, primary_key=True)
flow_id = models.IntegerField(blank=True, null=True)
currency_id = models.SmallIntegerField(blank=True, null=True)
contractor = models.ForeignKey(Contractors, blank=True, null=True, on_delete=models.CASCADE)
amount = models.IntegerField(blank=True, null=True)
callback_url = models.CharField(max_length=128, blank=True, null=True)
definition = models.TextField(blank=True, null=True) # This field type is a guess.
name = models.CharField(max_length=255, blank=True, null=True)
description = models.TextField(blank=True, null=True)
charge_strategy = models.CharField(max_length=64, blank=True, null=True)
routine = models.TextField(blank=True, null=True) # This field type is a guess.
tags = models.TextField(blank=True, null=True) # This field type is a guess.
class Meta:
managed = False
db_table = '"processing"."service"'
class Transaction(models.Model):
id = models.BigIntegerField(blank=True, null=False, primary_key=True)
currency = models.ForeignKey(Currency, null=True, on_delete=models.CASCADE)
deal = models.ForeignKey(Deal, null=True, on_delete=models.CASCADE)
service_instance = models.ForeignKey(ServiceInstance, null=True, on_delete=models.CASCADE)
payment_source = models.ForeignKey(PayerPaymentSource, null=True, on_delete=models.CASCADE)
payment_date = models.DateTimeField(blank=True, null=True)
amount = models.IntegerField(blank=True, null=True)
status = models.CharField(max_length=255, blank=True, null=True)
context = models.TextField(blank=True, null=True)
class Meta:
managed = False
db_table = '"processing"."transaction"'
You can use defer to not load up the fields from related models:
https://docs.djangoproject.com/en/2.2/ref/models/querysets/#defer
So a (not complete) modification of your query to remove currency name:
paymentsss = Transaction.objects.all().select_related('currency', 'payment_source__payment_type', 'deal__service','deal__service__contractor').defer('currency__name')
I decided this by simply deleting the fields I did not need from the model.

Django models.ForeignKey issue with model with custom foreign key

I use Django 1.11, Python 3.6 and PostgreSQL 9.6.
I define two models as described in the documentation.
class CircDetect(models.Model):
oid = models.AutoField(primary_key=True)
...
class Meta:
db_table = 'circdetect'
class PatientMed(models.Model):
...
circdetect = models.ForeignKey(CircDetect, on_delete=models.CASCADE, to_field='oid')
...
But when I try to get an access to the list of PatientMed objects on the admin site I get an exception:
ProgrammingError at /canreg/editor/patientmed/
column patient_med.circdetect_id does not exist
LINE 1: ... "patient_info"."id") INNER JOIN "circdetect" ON ("patient_m...
HINT: Perhaps you meant to reference the column "patient_med.circdetect".
It looks like Django tries to get id filed of circdetect, which is actually has name oid.
What can I do to fix this issue?
EDITED on 21 jul
As Ahmad took note below, I have an another model, that I didn't mention. I'm not sure it affects on the error in this case but this is that model:
class PatientInfo(models.Model):
...
class Meta:
db_table = 'patient_info'
And PatientMed is connected with PatientInfo this way:
class PatientMed(models.Model):
info = models.OneToOneField(PatientInfo, on_delete=models.CASCADE, primary_key=True)
...
But it works without any problems.
I should say, that circdetect is a legacy table, that I already had in my database when I started work.
EDITED
I use this code to show PatientMed objects in the admin site:
class PatientMedAdmin(admin.ModelAdmin):
list_display = (
'info',
...
'circdetect',
...
)
list_per_page = 25
admin.site.register(models.PatientMed, PatientMedAdmin)
EDITED
As Alasdair ask below I put here full models. There is no secret in them, but they are big
class CircDetect(models.Model):
oid = models.AutoField(primary_key=True)
code = models.SmallIntegerField(blank=True, null=True)
txt = models.CharField(max_length=50, blank=True, null=True)
class Meta:
db_table = 'circdetect'
ordering = ['code']
class PatientInfo(models.Model):
objects = models.Manager()
first_name = models.CharField(max_length=50, blank=True, null=True)
last_name = models.CharField(max_length=50, blank=True, null=True)
patronymic = models.CharField(max_length=50, blank=True, null=True)
birth_date = models.DateField(blank=True, null=True)
zip_code = models.CharField(max_length=6, blank=True, null=True)
address = models.TextField(blank=True, null=True)
home_phone = models.CharField(max_length=11, blank=True, null=True)
cell_phone = models.CharField(max_length=11, blank=True, null=True)
e_mail = models.EmailField(null=True)
def __str__(self):
return u'%s %s %s %s' % (to_str(self.last_name), to_str(self.first_name),
to_str(self.patronymic), to_str(self.birth_date))
class Meta:
db_table = 'patient_info'
class PatientMed(models.Model):
objects = models.Manager()
info = models.OneToOneField(PatientInfo, on_delete=models.CASCADE, primary_key=True)
center = models.SmallIntegerField(blank=True, null=True)
sex = models.SmallIntegerField(blank=True, null=True)
fddate = models.DateField(blank=True, null=True)
tsdate = models.DateField(blank=True, null=True)
tdate = models.DateField(blank=True, null=True)
edate = models.DateField(blank=True, null=True)
otcode = models.SmallIntegerField(blank=True)
ddate = models.DateField(blank=True, null=True)
death_icd = models.CharField(max_length=7, blank=True, null=True)
ecode = models.SmallIntegerField(blank=True, null=True)
esource = models.SmallIntegerField(blank=True, null=True)
dcause = models.SmallIntegerField(blank=True, null=True)
dsource = models.SmallIntegerField(blank=True, null=True)
numtumor = models.SmallIntegerField(blank=True, null=True)
iccc = models.CharField(max_length=3, blank=True, null=True)
icd_10 = models.CharField(max_length=7, blank=True, null=True)
icd_o = models.CharField(max_length=5, blank=True, null=True)
fds = models.TextField(blank=True, null=True)
circdetect = models.ForeignKey(to=CircDetect, on_delete=models.CASCADE, to_field='oid')
hyst = models.CharField(max_length=5, blank=True, null=True)
cyto = models.CharField(max_length=5, blank=True, null=True)
exp_oper = models.CharField(max_length=5, blank=True, null=True)
immun = models.CharField(max_length=5, blank=True, null=True)
cytogen = models.CharField(max_length=5, blank=True, null=True)
lab_instr = models.CharField(max_length=5, blank=True, null=True)
incentr = models.CharField(max_length=5, blank=True, null=True)
lasttest = models.DateField(blank=True, null=True)
lastsource = models.SmallIntegerField(blank=True, null=True)
lfudate = models.DateField(blank=True, null=True)
lfucode = models.SmallIntegerField(blank=True, null=True)
otregion = models.CharField(max_length=5, blank=True, null=True)
date_actend = models.DateField(blank=True, null=True)
concord = models.SmallIntegerField(blank=True, null=True)
protocol = models.CharField(max_length=10, blank=True, null=True)
autopsie = models.CharField(max_length=5, blank=True, null=True)
tabort = models.SmallIntegerField(blank=True, null=True)
stage = models.SmallIntegerField(blank=True, null=True)
stage_sym = models.CharField(max_length=4, blank=True, null=True)
chirurg = models.CharField(max_length=5, blank=True, null=True)
radiolog = models.CharField(max_length=5, blank=True, null=True)
chimio = models.CharField(max_length=5, blank=True, null=True)
rdate = models.DateField(blank=True, null=True)
rem = models.TextField(blank=True, null=True)
t_tnm = models.SmallIntegerField(blank=True, null=True)
n_tnm = models.SmallIntegerField(blank=True, null=True)
m_tnm = models.SmallIntegerField(blank=True, null=True)
g_tnm = models.SmallIntegerField(blank=True, null=True)
encr_bas = models.SmallIntegerField(blank=True, null=True)
ct_tnm = models.SmallIntegerField(blank=True, null=True)
cn_tnm = models.SmallIntegerField(blank=True, null=True)
cm_tnm = models.SmallIntegerField(blank=True, null=True)
land = models.IntegerField(blank=True, null=True)
lum = models.CharField(max_length=5, blank=True, null=True)
oss = models.CharField(max_length=5, blank=True, null=True)
hepar = models.CharField(max_length=5, blank=True, null=True)
lung = models.CharField(max_length=5, blank=True, null=True)
brain = models.CharField(max_length=5, blank=True, null=True)
skin = models.CharField(max_length=5, blank=True, null=True)
nephro = models.CharField(max_length=5, blank=True, null=True)
herm = models.CharField(max_length=5, blank=True, null=True)
periton = models.CharField(max_length=5, blank=True, null=True)
kmark = models.CharField(max_length=5, blank=True, null=True)
unknown = models.CharField(max_length=5, blank=True, null=True)
other = models.CharField(max_length=5, blank=True, null=True)
acc = models.IntegerField()
class Meta:
db_table = 'patient_med'
It sounds like you have to specify db_column, to let Django know the name of the column in the PatientMed column.
class PatientMed(models.Model):
circdetect = models.ForeignKey(CircDetect, on_delete=models.CASCADE, db_column='circdetect', to_field='oid')
You haven't written the instruction that makes the error. But it seems that you have another table named PatientInfo that the error is related to.
I'm not sure what was the cause of the problem. I solved it by dropping my database and recreating it and my entities.
Thank you everyone.