Re: Facing Issue with ODBC Driver 17 for SQL Server

2023-02-10 Thread David Nugent

Hi Sahan,

"the target machine actively refused it” - in TCP parlance, that means 
that there’s nothing listening on that port, aka “connection refused”. 
The server you are trying to connect to isn’t there (or there is a 
firewall similar blocking the connection - but doubt it).


IIRC by default SQL Server runs each instance on its own port, and uses 
a broker (aka “browser service”) to determine which instance you are 
connecting to (on port 1434?). See this link for more info:


https://learn.microsoft.com/en-us/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access?view=sql-server-ver16

Again, from memory (which may not be accurate), each instance may have a 
“dynamic port” allocated but will consistently expose itself on the same 
port each time it is started. So locking in a particular port in Django 
is normally ok. You just need to determine what port that is. :-)


The db connector in Django knows or understands the dynamic connection 
strategy that SQL Server uses, but needs the port number directly 
assigned to the instance..


HTH,
/d


-- Original Message --

From "Sahan Srinivas" <26sa...@gmail.com>

To "Django users" 
Date 2/11/2023 3:48:49 AM
Subject Facing Issue with ODBC Driver 17 for SQL Server


Hi All,

I am facing an issue with the DJANGO SQL Driver below is the 
screenshot, It is showing the error as


django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][ODBC 
Driver 17 for SQL Server]TCP Provider: No connection could be made 
because the target machine actively refused it.\r\n (10061) 
(SQLDriverConnect)


Below are my Database details in settings.py file.

DATABASES ={
'default':{
'ENGINE':"sql_server.pyodbc",
'NAME':"IRIS",
'USER':"sa",
'PASSWORD':'admin123#',
'HOST':'Pegasus\MSSQLSERVER2022',
'PORT':'1433',
'OPTIONS':{
'driver':'ODBC Driver 17 for SQL Server',
},
  },
}

Can anyone help me out? The driver's are installed, the same I can run 
using SQL alchemy


Kind Regards,
Sahan



--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/208fbabc-c1c9-4770-8428-0679927a6005n%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/em38f13ab2-5dc4-4215-bc66-117f4dd523a5%403845105e.com.


pgphTcO8orPEF.pgp
Description: PGP signature


django-formset 0.13.2 I am facing the issue  VM55:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "

2023-02-10 Thread 6C40 MAHALAKSHMI S
this is my code

form.py

class OfficedetForm(forms.ModelForm):
office_logo = fields.FileField(
label="Office Logo",
widget=UploadedFileInput,
required=True,
)

office_gender_type = forms.ModelChoiceField(
queryset=OFFICE_GENDER_TYPE_CHOICE.objects.all(),
widget=Selectize(
placeholder="Choose Gender",
),
)

office_mgnt_type = forms.ModelChoiceField(
queryset=OFFICE_MGNT_TYPE_CHOICE.objects.all(),
widget=Selectize(
placeholder="Choose Management",
),
)

office_class_level = forms.ModelChoiceField(
queryset=OfficeClassLevel.objects.all(),
widget=Selectize(
placeholder="Choose Class Level",
),
)

office_place = forms.ModelChoiceField(
queryset=Places.objects.all(),
widget=Selectize(
search_lookup='placename__icontains',
placeholder="Choose Place",
),
)

office_type = forms.ChoiceField(
choices=[ ('SCHOOL','SCHOOL'),
('ADMIN','ADMIN'),],
widget=Selectize,
)


default_renderer = FormRenderer(
form_css_classes='row',
field_css_classes={
'*': 'mb-2 col-12', 
"office_code": 'mb-2 col-2', 
"office_name": 'mb-2 col-4',
"office_mail": 'mb-2 col-3',
"office_place": 'mb-2 col-3',
'*': 'mb-2 col-12', 
"office_gender_type": 'mb-2 col-3', 
"office_mgnt_type": 'mb-2 col-3',
"office_class_level": 'mb-2 col-3',
"office_type": 'mb-2 col-3',

'*': 'mb-2 col-12', 
"office_tanno": 'mb-2 col-4', 
"office_udisecode": 'mb-2 col-4', 
"office_logo": 'mb-2 col-4', 


}
)
class Meta:
model = Officedet
fields = ["office_code",
"office_name",
"office_mail",
"office_place",
"office_gender_type",
"office_mgnt_type",
"office_class_level",
"office_type",
'office_tanno',
'office_udisecode',
"office_logo",
]


views.py

class OfficeDetailCreateView(AdminUserTypeAuthMixin,FileUploadMixin, 
FormViewMixin, LoginRequiredMixin, CreateView):
model = Officedet
template_name = 'home/crud/crud_template.html'
form_class = OfficedetForm
success_url = reverse_lazy('office_list_view') # or whatever makes sense
extra_context = {
'pagetitle':'Office Creation'
}


page.html
{% extends "layouts/masterpage-formset.html" %}
{% block pagecontent %}
{% load render_form from formsetify %}

{% render_form form %}


Submit
Reset
Back to 
list


{% endblock pagecontent %}


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/92d2c8c6-53a6-40a6-b8c8-9349c51eeb3fn%40googlegroups.com.


Re: django model method

2023-02-10 Thread Gabriel Araya Garcia
Allways there is a way to improve the code, but  if that not run, then try
with CYTHON

Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos




El jue, 9 feb 2023 a las 10:09, Andréas Kühne ()
escribió:

> Not if you want it to be fast. Python itself is slow - so you should try
> to offload most of the computation on the database. So filtering would need
> to be done on database fields as well.
>
> Otherwise you would need to load all of the rows into memory and then do
> the filtering there.
>
> If you want to continue along the route you have taken now - you probably
> could solve it with annotated queries - something like this:
>
> https://stackoverflow.com/questions/1396264/how-to-sort-by-annotated-count-in-a-related-model-in-django
>
> Regards,
>
> Andréas
>
>
> Den tors 9 feb. 2023 kl 13:21 skrev Chelsea Fan <
> allaberdi16yazha...@gmail.com>:
>
>> understood, is there any way to filter objects by method value?
>>
>> On Thu, Feb 9, 2023 at 4:42 PM Andréas Kühne 
>> wrote:
>>
>>> No.
>>>
>>> Ordering works by using the database to order the models. It therefore
>>> needs to be a database field - otherwise the database can't order by the
>>> field?
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den tors 9 feb. 2023 kl 12:09 skrev Chelsea Fan <
>>> allaberdi16yazha...@gmail.com>:
>>>
 hello guys, Is it possible to use model method value to ordering model
 objects in meta class?

 class Post(models.Model):
 title = models.CharField(max_length=255, verbose_name="ady")
 text = RichTextField(verbose_name="text")
 tagList = models.ManyToManyField(Tag, verbose_name="taglar",
 related_query_name="tagList")
 image = models.ImageField(upload_to="postImage/", verbose_name=
 "surat")
 seen = models.ManyToManyField(UserId,verbose_name="görülen sany",
 blank=True, related_name="gorulen")
 like = models.ManyToManyField(UserId,verbose_name="like sany",
 blank=True)
 share = models.PositiveIntegerField(verbose_name="paýlaşylan sany",
 null=True, blank=True, default="0")
 createdAt = models.DateTimeField(auto_now_add=True, 
 verbose_name="goşulan
 güni")

 class Meta:
 verbose_name_plural="Makalalar"
 # ordering = ("-createdAt",)
 ordering = ["-hotness",]

 def __str__(self):
 return self.title

 def likes(self):
 return self.like.count()

 likes.short_description = "Like sany"
 likes.allow_tags = True

 def seens(self):
 return self.seen.count()

 seens.short_description = "Görülen sany"
 seens.allow_tags = True

 @property
 def hotness(self):
 return self.likes() + self.seens() + self.share

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAJwZndfmes4g2KWUB3Fz6wNRORQ40Fxj_NYwYKWCF6DX96OVyg%40mail.gmail.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAK4qSCfpaVQ1YXMbVae26RLgsYYBcLRMcpgQOEm9z3%2B6NpN5Ww%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAJwZnddOzyjuawMFe4pZtn4oj8YxZDBX_N1SK492G3RhENyVqg%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK4qSCf02LMA9tN_AEijDnM58PcT1uk8Q0zmr%2BORBc_bZXwSaA%40mail.gmail.com
>