NoReverseMatch at /doctorAcc - django

django.urls.exceptions.NoReverseMatch: Reverse for 'doctorAcc' with arguments '({' '})' not found. 1 pattern(s) tried: ['doctorAcc\Z'].
I got this error while redirecting and rendering in django. I want redirect to stop resubmit form while refreshing.
views.py
def doctorAcc(request):
if request.method == "POST":
docname = request.POST.get("doctor_name")
department = request.POST.get("department")
location = request.POST.get("location")
working_H = request.POST.get("working_H")
brife = request.POST.get("brife")
clinicloc = request.POST.get("clinicloc")
nw_pat_fee = request.POST.get("nw_pat_fee")
ret_pat_fee = request.POST.get("ret_pat_fee")
repo_fee = request.POST.get("repo_fee")
lag_spoken = request.POST.get("lag_spoken")
sunday_mor = request.POST.get("sunday_mor")
sunday_ev = request.POST.get("sunday_ev")
monday_mor = request.POST.get("monday_mor")
monday_ev = request.POST.get("monday_ev")
tuesday_mor = request.POST.get("tuesday_mor")
tuesday_ev = request.POST.get("tuesday_ev")
wedday_mor = request.POST.get("wedday_mor")
wedday_ev = request.POST.get("wedday_ev")
thursday_mor = request.POST.get("thursday_mor")
thursday_ev = request.POST.get("thursday_ev")
frday_mor = request.POST.get("frday_mor")
frday_ev = request.POST.get("frday_ev")
satday_mor = request.POST.get("satday_mor")
satday_ev = request.POST.get("satday_ev")
image=request.POST.get("image")
obj = NearBy_Doctor(doctor_name = docname, department = department, location=location,working_H = working_H,brife = brife,clinicloc = clinicloc,nw_pat_fee = nw_pat_fee
,ret_pat_fee = ret_pat_fee,repo_fee = repo_fee,lag_spoken = lag_spoken,sunday_mor = sunday_mor,sunday_ev = sunday_ev
,monday_mor = monday_mor,monday_ev = monday_ev,tuesday_mor = tuesday_mor,tuesday_ev = tuesday_ev,wedday_mor = wedday_mor
,wedday_ev = wedday_ev,thursday_mor = thursday_mor,thursday_ev = thursday_ev,frday_mor = frday_mor
,frday_ev = frday_ev,satday_mor = satday_mor,satday_ev = satday_ev,image = image)
obj.save()
return redirect ('doctorAcc', {'docname':docname,'department':department,'location':location,'working_H':working_H,'brife':brife,'clinicloc':clinicloc
,'nw_pat_fee':nw_pat_fee,'ret_pat_fee':ret_pat_fee,'repo_fee':repo_fee,'lag_spoken':lag_spoken,'sunday_mor':sunday_mor
,'monday_mor':monday_mor,'monday_mor':monday_mor,'monday_ev':monday_ev,'tuesday_mor':tuesday_mor,'tuesday_ev':tuesday_ev,'wedday_mor':wedday_mor
,'wedday_ev':wedday_ev,'thursday_mor':thursday_mor,'thursday_ev':thursday_ev,'frday_mor':frday_mor,'frday_ev':frday_ev,'satday_mor':satday_mor,'satday_ev':satday_ev,'image':image} )
if request.method =="GET":
docname = NearBy_Doctor.doctor_name
# docname = request.GET.get("doctor_name")
department = request.GET.get("department")
location = request.GET.get("location")
working_H = request.GET.get("working_H")
brife = request.GET.get("brife")
clinicloc = request.GET.get("clinicloc")
nw_pat_fee = request.GET.get("nw_pat_fee")
ret_pat_fee = request.GET.get("ret_pat_fee")
repo_fee = request.GET.get("repo_fee")
lag_spoken = request.GET.get("lag_spoken")
sunday_mor = request.GET.get("sunday_mor")
sunday_ev = request.GET.get("sunday_ev")
monday_mor = request.GET.get("monday_mor")
monday_ev = request.GET.get("monday_ev")
tuesday_mor = request.GET.get("tuesday_mor")
tuesday_ev = request.GET.get("tuesday_ev")
wedday_mor = request.GET.get("wedday_mor")
wedday_ev = request.GET.get("wedday_ev")
thursday_mor = request.GET.get("thursday_mor")
thursday_ev = request.GET.get("thursday_ev")
frday_mor = request.GET.get("frday_mor")
frday_ev = request.GET.get("frday_ev")
satday_mor = request.GET.get("satday_mor")
satday_ev = request.GET.get("satday_ev")
image=request.GET.get("image")
return render(request,'doctorAcc.html',{'docname':docname,'department':department,'location':location,'working_H':working_H,'brife':brife,'clinicloc':clinicloc
,'nw_pat_fee':nw_pat_fee,'ret_pat_fee':ret_pat_fee,'repo_fee':repo_fee,'lag_spoken':lag_spoken,'sunday_mor':sunday_mor
,'monday_mor':monday_mor,'monday_mor':monday_mor,'monday_ev':monday_ev,'tuesday_mor':tuesday_mor,'tuesday_ev':tuesday_ev,'wedday_mor':wedday_mor
,'wedday_ev':wedday_ev,'thursday_mor':thursday_mor,'thursday_ev':thursday_ev,'frday_mor':frday_mor,'frday_ev':frday_ev,'satday_mor':satday_mor,'satday_ev':satday_ev,'image':image})
urls.py
urlpatterns = [
# path('admin/', admin.site.urls),
path('doctorAcc',views.doctorAcc,name = 'doctorAcc'),
]
models.py
class NearBy_Doctor(models.Model):
doctor_name = models.CharField(max_length=122)
department = models.CharField(max_length=122)
location = models.CharField(max_length=122)
working_H = models.CharField(max_length=122)
brife =models.TextField()
clinicloc = models.CharField( max_length=122)
nw_pat_fee = models.CharField( max_length=122)
ret_pat_fee = models.CharField( max_length=122)
repo_fee = models.CharField( max_length=122)
lag_spoken = models.CharField( max_length=122)
sunday_mor = models.CharField( max_length=122)
sunday_ev = models.CharField( max_length=122)
monday_mor = models.CharField( max_length=122)
monday_ev = models.CharField( max_length=122)
tuesday_mor = models.CharField( max_length=122)
tuesday_ev = models.CharField( max_length=122)
wedday_mor = models.CharField( max_length=122)
wedday_ev = models.CharField( max_length=122)
thursday_mor = models.CharField( max_length=122)
thursday_ev = models.CharField( max_length=122)
frday_mor = models.CharField( max_length=122)
frday_ev = models.CharField( max_length=122)
satday_mor = models.CharField( max_length=122)
satday_ev = models.CharField( max_length=122)
image=models.ImageField( null=True,blank=True)
def __str__(self):
return self.doctor_name
I get this error while redirect and render in django.

Related

Django ORM query for filtering product price between two number is not working properly

class Product(models.Model):
product_name = models.CharField(max_length=255,unique=True)
slug = models.SlugField(max_length=255)
brand = models.CharField(max_length=255)
price = models.CharField(max_length=255)
product_image_1 = models.ImageField(upload_to = 'photos/product',blank = False)
product_image_2 = models.ImageField(upload_to = 'photos/product', blank = False)
product_image_3 = models.ImageField(upload_to = 'photos/product', blank = False)
product_image_4 = models.ImageField(upload_to = 'photos/product',blank = False)
product_description = models.TextField()
category_id = models.ForeignKey(Categories,on_delete=models.CASCADE)
subcategory_id = models.ForeignKey(SubCategories, on_delete=models.CASCADE)
stock = models.IntegerField(default=0)
created_at = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
def __str__(self):
return self.product_name
def get_url(self):
return reverse('product_detail',args = [self.category_id.slug , self.subcategory_id.slug,
self.slug ])
'''view'''
val=request.POST.get('value')
val = re.findall("\d+", val) # code to get all inigers from string
min_price = int(val[0])
max_price = int(val[1])
print(min_price)
print(max_price)
***product = Product.objects.filter(category_id = categories,is_active =
True,price__gte = min_price, price__lte = max_price)***
when i give value greater than max_value product object returns null object
I want all objects between the two min_value and max_value

How to update a model query

i'm developing a web app that will guide the student what to choose on his next year , if the general average > 12 and specialite ==Si he can choose Si else he is obliged to choose ISIL
i want to update the specialite into ISIL
PS : im new at django
views.py :
def resultats(request,id=None):
etudiant = MyUser.objects.all
etud_si = MyUser.objects.all().filter(specialite='SI')
etud_isil = MyUser.objects.all().filter(specialite='ISIL')
moy = MyUser.objects.all().annotate(moyenne =(F('moyenne_s1')+F('moyenne_s2'))/2).filter(moyenne__gt=11.99,specialite='SI')
moy1 = MyUser.objects.all().annotate(moyenne =(F('moyenne_s1')+F('moyenne_s2'))/2).filter(moyenne__lt=11.99,specialite='SI')
if moy1 :
moy1.specialite = 'ISIL'
moy1.save()
if id:
pr = get_object_or_404(MyUser,id=id)
else:
pr = request.user
context = {
'etudiant':etudiant,
'profile':pr,
'etud_si':moy,
'etud_isil':moy1
}
return render(request,'resultats.html',context)
models.py :
class MyUser(AbstractBaseUser,PermissionsMixin):
SI = 'SI'
ISIL = 'ISIL'
SPEC_CHOICES = [
(SI,'SI - System Informatique'),
(ISIL,'ISIL - Ingenieur system informatique et logiciels')
]
username = models.CharField(
max_length=300,
validators = [
RegexValidator(regex = USERNAME_REGEX,
message = 'Nom d\'utilisateur doit etre Alphanumeric',
code = 'nom d\'utilisateur invalid'
)],
unique = True
)
email = models.EmailField(unique = True)
nom = models.CharField(default=' ',max_length=300)
prenom = models.CharField(default=' ',max_length=300)
moyenne_s1 =models.DecimalField(default=00.00,max_digits=4,decimal_places=2)
moyenne_s2 = models.DecimalField(default=00.00,max_digits=4,decimal_places=2)
specialite = models.CharField(max_length=300,choices=SPEC_CHOICES,default=SI)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email','moyenne_s1','moyenne_s2']
def get_update(self):
return reverse("edit", kwargs={"id": self.id})
#property
def moyenne_gen(self):
return (self.moyenne_s1+self.moyenne_s2)/2
I Solved it :
def resultats(request,id=None):
etudiant = MyUser.objects.all
moy = MyUser.objects.all().annotate(moyenne =(F('moyenne_s1')+F('moyenne_s2'))/2).filter(moyenne__gt=11.99,specialite='SI')
moy1 = MyUser.objects.all().annotate(moyenne =(F('moyenne_s1')+F('moyenne_s2'))/2).filter(moyenne__lt=11.99)
if moy1 :
moy1.specialite = 'ISIL'
moy1.update(specialite='ISIL')
if id:
pr = get_object_or_404(MyUser,id=id)
else:
pr = request.user
context = {
'etudiant':etudiant,
'profile':pr,
'etud_si':moy,
'etud_isil':moy1
}
return render(request,'resultats.html',context)

My create view is neither saving the object nor redirecting to the next page?

I made a create view that should be able to save an object and then redirect bit form some reasons the form is not valid and it's not saving the object. If anybody knows the answer then please write the whole answer with code.
My create view
class Submit_Property(generic.CreateView):
model = models.Property
form_class = forms.Property_Form
template_name = 'profile_details/submit-property.html'
Here's the model for This
class Property(models.Model):
title = models.CharField(max_length = 210,default = 'None')
STATUS_CHOICES = (
('RENT','Rent'),
('SALE','Sale'),
)
status = models.CharField(max_length = 210,choices = STATUS_CHOICES,default = 'Rent')
price = models.IntegerField()
area = models.CharField(max_length = 210,default = 'None')
ROOM_CHOICES = (
('1','1'),
('2','2'),
('3','3'),
('4','4'),
('MORE','More'),
)
rooms = models.CharField(max_length = 210,choices = ROOM_CHOICES,default = '1')
BATHROOM_CHOICES = (
('1','1'),
('2','2'),
('3','3'),
('4','4'),
)
bathroom = models.CharField(max_length = 210,choices = BATHROOM_CHOICES,default = '2')
address = models.CharField(max_length = 210,default = 'None')
state = models.CharField(max_length = 210,default = 'None')
code = models.CharField(max_length = 210,default = 'None')
images = models.ImageField(upload_to = 'images',)
info = models.TextField(max_length = 1000,default = 'None')
parking = models.BooleanField(default = False,verbose_name = 'Parking')
air = models.BooleanField(default = False)
swimming = models.BooleanField(default = False)
laundry = models.BooleanField(default = False)
dealer_name = models.CharField(max_length = 210,default = 'None')
dealer_email = models.EmailField(max_length = 210,default = 'abc#gmail.com')
dealer_number = models.CharField(max_length = 210,default = 'Not mentioned')
user = models.ForeignKey(User,related_name = 'user',default = True)
timpestamp = models.DateTimeField(auto_now_add = True)
category = models.ManyToManyField(Category,related_name = 'categories',default = None)
def get_absolute_url(self,*args,**kwargs):
return reverse('profile_details:property')
def __str__(self):
return self.title
It's right here in form valid
def form_valid(self, form):
form.instance.user = self.request.user
form.save()
return super().form_valid(form)
But don't write like this
def form_valid(self, form):
form.instance.user = self.request.user
form.save()
return super(models.Property, self).form_valid(form)

why would my databse entries be coming up empty?

I'm trying to create new instances based off of the form below however when it saves, the database only saves the foreign key value and the order value but nothing else. Any Idea why?
models:
class danceType(models.Model):
eventtype = models.ForeignKey(compType)
dance_name = models.CharField(max_length = 20)
Price = models.FloatField(max_length = 7, null=True, blank=True )
field_2 = models.CharField(max_length = 20, null=True, blank=True)
def __unicode__(self):
fields = ('field_2')
return self.dance_name
class dancer(models.Model):
dancetype = models.ForeignKey(danceType)
e_number = models.IntegerField(max_length = 4, null=True, blank=True)
D1_first_name = models.CharField(max_length = 20)
D1_last_name = models.CharField(max_length = 20)
D1_email = models.EmailField(max_length = 20)
city = models.CharField(max_length = 20)
order = models.PositiveIntegerField()
perform = models.NullBooleanField(null=True, blank=True)
View:
if request.method =='POST':
sub_type = request.POST.get("form")
dancetype = request.POST.get("dancetype")
ext = request.POST.get("quantity")
form = modelformset_factory(dancer, form=CompReg, extra=int(ext))
productform = form(queryset = dancer.objects.none())
if sub_type == "submitted":
productform = form(request.POST, request.FILES)
if productform.is_valid():
for p in productform:
dance=p.save(commit=False)
dance.dancetype_id = 4
dance.order = 1
dance.save()
else:
der = "it didnt save"

django: daterangefield attribute error

I get this error 'int' object has no attribute 'days' in trace this is highlighted camp.save()
My model class:
class Campaign(models.Model):
time_to_next = DateTimeRangeField()
rank = models.PositiveIntegerField()
address = models.ForeignKey(Address)
description = models.CharField(max_length = 200)
display = models.BooleanField()
date_created = models.DateField(auto_now_add=True)
url = models.URLField()
current_promotion = models.ForeignKey(Promotion, related_name="campaign_current_promotion")
promotions = models.ManyToManyField(Promotion)
enabled = models.BooleanField()
My view:
camp = campaign.save(commit=False)
camp.business = bdns
camp.time_to_next = 2
camp.rank = 1
camp.address = addr
camp.display = 1
camp.url = 'http://test1.com'
camp.current_promotion = promo
camp.enabled = True
camp.save()
cp = promo
camp.promotions.add(cp)
what could be the issue?