Re: Testing django

2023-03-16 Thread Ayush Bisht
Yeah, I got you..
My concern is on the documentation, the way it has provided the commands
for executing test cases.

That
path.to.settings seems confusing sometimes..

On Fri, 17 Mar, 2023, 1:20 am Bhuvnesh Sharma, 
wrote:

> We can run django tests with custom settings by using --settings flag and
> providing the path to the custom settings file . For example:
> ./runtests.py --settings=new_app.test_settings
>
> What do you want to do exactly?
>
> On Fri, Mar 17, 2023 at 1:00 AM Ayush Bisht 
> wrote:
>
>> Seems like, it is for defining how actually we are selecting the specific
>> test case. It is very confusing at first.
>> Can't we just explain it with an example..
>>
>> On Friday, March 17, 2023 at 12:54:27 AM UTC+5:30 Ayush Bisht wrote:
>>
>>> * ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*
>>>
>>> what exactly is the purpose of *path.to.settings,* I'm getting an error
>>> while running the above line.
>>> Can anyone please explain?
>>>
>>> *Error*
>>> Testing against Django installed in '/home/ayush/OS/django/django' with
>>> up to 8 processes
>>> Traceback (most recent call last):
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
>>> failures = django_tests(
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 398, in
>>> django_tests
>>> test_labels, state = setup_run_tests(*process_setup_args)
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 300, in
>>> setup_run_tests
>>> test_modules, state = setup_collect_tests(
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 201, in
>>> setup_collect_tests
>>> "INSTALLED_APPS": settings.INSTALLED_APPS,
>>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in
>>> __getattr__
>>> self._setup(name)
>>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in
>>> _setup
>>> self._wrapped = Settings(settings_module)
>>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in
>>> __init__
>>> mod = importlib.import_module(self.SETTINGS_MODULE)
>>>   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in
>>> import_module
>>> return _bootstrap._gcd_import(name[level:], package, level)
>>>   File "", line 1050, in _gcd_import
>>>   File "", line 1027, in _find_and_load
>>>   File "", line 992, in
>>> _find_and_load_unlocked
>>>   File "", line 241, in
>>> _call_with_frames_removed
>>>   File "", line 1050, in _gcd_import
>>>   File "", line 1027, in _find_and_load
>>>   File "", line 992, in
>>> _find_and_load_unlocked
>>>   File "", line 241, in
>>> _call_with_frames_removed
>>>   File "", line 1050, in _gcd_import
>>>   File "", line 1027, in _find_and_load
>>>   File "", line 1004, in
>>> _find_and_load_unlocked
>>> ModuleNotFoundError: No module named 'path'
>>>
>> --
>> 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/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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/CA%2BZJHEqMWEj8dE9gpVW0f5QajXy1b9GPp-Qur4457GMoWAoUbQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2BZJHEqMWEj8dE9gpVW0f5QajXy1b9GPp-Qur4457GMoWAoUbQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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/CA%2B%2BM4H5-M%2B6T5PvfctNYJR7o0ebry_4f-JUGec8QewJs%2BhASNg%40mail.gmail.com.


Re: Testing django

2023-03-16 Thread Ayush Bisht
Seems like, it is for defining how actually we are selecting the specific 
test case. It is very confusing at first. 
Can't we just explain it with an example..

On Friday, March 17, 2023 at 12:54:27 AM UTC+5:30 Ayush Bisht wrote:

> * ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*
>
> what exactly is the purpose of *path.to.settings,* I'm getting an error 
> while running the above line.
> Can anyone please explain?
>
> *Error*  
> Testing against Django installed in '/home/ayush/OS/django/django' with up 
> to 8 processes
> Traceback (most recent call last):
>   File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
> failures = django_tests(
>   File "/home/ayush/OS/django/tests/./runtests.py", line 398, in 
> django_tests
> test_labels, state = setup_run_tests(*process_setup_args)
>   File "/home/ayush/OS/django/tests/./runtests.py", line 300, in 
> setup_run_tests
> test_modules, state = setup_collect_tests(
>   File "/home/ayush/OS/django/tests/./runtests.py", line 201, in 
> setup_collect_tests
> "INSTALLED_APPS": settings.INSTALLED_APPS,
>   File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in 
> __getattr__
> self._setup(name)
>   File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in _setup
> self._wrapped = Settings(settings_module)
>   File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in 
> __init__
> mod = importlib.import_module(self.SETTINGS_MODULE)
>   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in 
> import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 1050, in _gcd_import
>   File "", line 1027, in _find_and_load
>   File "", line 992, in 
> _find_and_load_unlocked
>   File "", line 241, in 
> _call_with_frames_removed
>   File "", line 1050, in _gcd_import
>   File "", line 1027, in _find_and_load
>   File "", line 992, in 
> _find_and_load_unlocked
>   File "", line 241, in 
> _call_with_frames_removed
>   File "", line 1050, in _gcd_import
>   File "", line 1027, in _find_and_load
>   File "", line 1004, in 
> _find_and_load_unlocked
> ModuleNotFoundError: No module named 'path'
>

-- 
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/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com.


Testing django

2023-03-16 Thread Ayush Bisht
* ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*

what exactly is the purpose of *path.to.settings,* I'm getting an error 
while running the above line.
Can anyone please explain?

*Error*  
Testing against Django installed in '/home/ayush/OS/django/django' with up 
to 8 processes
Traceback (most recent call last):
  File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
failures = django_tests(
  File "/home/ayush/OS/django/tests/./runtests.py", line 398, in 
django_tests
test_labels, state = setup_run_tests(*process_setup_args)
  File "/home/ayush/OS/django/tests/./runtests.py", line 300, in 
setup_run_tests
test_modules, state = setup_collect_tests(
  File "/home/ayush/OS/django/tests/./runtests.py", line 201, in 
setup_collect_tests
"INSTALLED_APPS": settings.INSTALLED_APPS,
  File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in 
__getattr__
self._setup(name)
  File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in _setup
self._wrapped = Settings(settings_module)
  File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in 
__init__
mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in 
import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 992, in _find_and_load_unlocked
  File "", line 241, in 
_call_with_frames_removed
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 992, in _find_and_load_unlocked
  File "", line 241, in 
_call_with_frames_removed
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 1004, in 
_find_and_load_unlocked
ModuleNotFoundError: No module named 'path'

-- 
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/f3d46fc7-0b31-4f28-844a-16462982a439n%40googlegroups.com.


Proxy Models in ForeignKey field

2022-10-14 Thread Ayush Bisht
Hey everyone, 
I need a help, regarding use of proxy models at foreignKey field.

class User(AbstractUser):
   is_customer  = models.BooleanField(default=False)
  ...

class Customer(User):
   objects = CustomerManger() # get_queryset will filtered out all the 
models based on 
is_customer 
field at User
class Meta:
proxy = True

class Subscription(models.Model):
user = models.ForeignKey(Customer)


so, my question is that is there a way  to allow subscription model to be 
only created with instance of Customer model and not any other User model 
which is not Customer model.




-- 
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/91c357b3-9628-4393-88a5-7029f7ae7565n%40googlegroups.com.


Re: Allow field validation in ajax.

2021-06-17 Thread Ayush Bisht
If you specifically trying to validate the form on the basis of empty input 
field, then simply include  *required* attribute in you input field
 **
and for more validation , you just validate all the thing in HTML only 
using django template tags... 
here I am including a descent approach ... 

 {% csrf_token %}
{% load bootstrap_tags %} 
   {{form.non_field_errors}}
   

 
   
   
   
 
  
*{% if form.username.errors %}*
*  {{form.username.errors}}  *
*  {% endif %}*
  Username  
   {{form.username}}
   


   
 
*   {% if form.email.errors %}*
*   {{form.email.errors}}  *
*   {% endif %}*
   Email   
  {{form.email}}
   


   


*   {% if form.password1.errors %}*
*   {{form.password1.errors}}  *
* {% endif %}*
   Enter the Password  
   
  {{form.password1}}
   


   

*   {% if form.password2.errors %} *
* {{form.password2.errors}}*
*   {% endif %} *
 Confirm Password
 

 {{form.password2}}
   
   
 
   
 
   *{% if form.captcha.errors %} *
* {{form.captcha.errors}}*
*   {% endif %}  *   
  Captcha
   {{form.captcha}}
 
 

   Register



if any validation error has caught , then it will shown at 
*{{form.captcha.errors}}*




On Thursday, June 17, 2021 at 4:04:48 AM UTC-7 eugenet...@gmail.com wrote:

> Dear NA,
>
> still it does not wark
>
> On Sun, 13 Jun 2021 at 03:20, Nikeet NA  wrote:
>
>> You are not submitting your form which Inturn is not validating. For 
>> validations to run you need to submit a form.
>>
>> Give the submit button attribute type="submit", then add an event 
>> listener for form submit in your javascript.
>> $("#ReportForm").on('submit', function(event) {
>>// here event is submit type event object
>>event.preventDefault() // this is added to prevent default 
>> execution of form submit event which will stop the page reload. 
>>// here event.target is your form so you can use that to get data 
>> as let data = new FormData(event.target) 
>> })
>>
>> On Saturday, 12 June 2021 at 22:09:26 UTC+5:30 eugenet...@gmail.com 
>> wrote:
>>
>>> Friends,
>>>
>>> The ajax codes below successfully save the records in the database 
>>> without page loading. But what I want is to validate the fields first 
>>> before saving. The codes do not validate the empty field. How can I include 
>>> that validation ? please help
>>>
>>> 
>>> $(".submit_btn").click(function(){
>>> var form=new FormData($("#ReportForm")[0]);
>>> //AJAX CODE
>>> var xhr=new XMLHttpRequest();
>>> xhr.onreadystatechange=function(){
>>> if(xhr.status==200){
>>> console.log(xhr.responseText);
>>> }
>>> }
>>> xhr.open("POST","{% url 'report_create' %}",true);
>>> $("#progressbar").show();
>>>
>>> //UPDATING PROGRESS BAR
>>> xhr.upload.addEventListener("progress",function(ev){
>>> if(ev.lengthComputable){
>>> var percentage=(ev.loaded/ev.total*100|0);
>>> $("#progressbar").css({"width":""+percentage+"%"}).text("Uploading .."+
>>> percentage+"%");
>>> console.log(percentage);
>>> if(percentage>=100){
>>> location.reload()
>>>
>>> }
>>> }
>>> });
>>>
>>> xhr.send(form);
>>> })
>>> 
>>>
>>> Regards,
>>> *Eugene*
>>>
>>>
>>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d4c70f2f-2b3f-4d64-a94a-ee31b9ecdd03n%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> *TUYIZERE Eugene*

Re: In need of urgent help regarding dynamic image display v

2021-06-17 Thread Ayush Bisht
I think there is 2 method which you can do to get the work done. ...

*1 : first one* .. you can declare a property decorator which just return 
the url of that image 

 
  class Banner(BaseModel):
image = ResizedImageField(upload_to="banner", null=True, 
blank=True)

@property
  def get_image_url(self):
  return str(self.image.url).replace(" ", "")
 
and then you can simply access this function like normal attributes.. 

 
{% for banner in banners %}

{% endfor %}




*2 Method :  *you can create a   root path for static files as well 

 
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]


now , with this root path I can access all the file belonging to that 
particular folder 

folder structure ... 

* static
   *Banner
 *banner1.jpg



now u can simply access all the stuff ...

.banner-item-01 {
padding:300px 0px;
background-size: cover;
background-image: url('/static/Banner/banner1.jpg');
background-repeat: no-repeat;
background-position: center center;
} 

On Thursday, June 17, 2021 at 4:11:11 AM UTC-7 arit...@gmail.com wrote:

> Hi, 
> I've been building a Django E-commerce website and I'm facing this problem.
> I have created a Banner model which will take in images via 
> django.ResizedImage and then display it in the homepage. But I'm unable to 
> process them in CSS.
> Kindly help me out.
>
> PS: I'll have to process it as background-image orelse when passed as 
>  in html, we're getting extra wrapped spaces which aren't needed.
>
> Below given are: views.py, models.py, index.html, css block. 
> Kindly help me out as it is urgent. Thank you for your support in advance.
>
> Regards,
> Aritra
>
> class HomeView(ListView):
> context_object_name = 'items'
> template_name = "index.html"
> queryset = Items.objects.all()
>
> def get_context_data(self, **kwargs):
> context = super(HomeView, self).get_context_data(**kwargs)
> context['banners'] = Banner.objects.all()
> return context
>
> class Banner(BaseModel):
> image = ResizedImageField(upload_to="banner", null=True, blank=True)
>
> 
> 
>   {% for banner in banners %}
> 
>   {% endfor %}
> 
> 
>
>   .banner-item-01 {
>padding:300px 0px;
>background-size: cover;
>background-image: url(var(--item));
>background-repeat: no-repeat;
>background-position: center center;
> }  
>
>
>

-- 
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/241a1f08-a093-4f3a-a01f-46e0a3e73ce1n%40googlegroups.com.


Re: Adding Two Models In Django

2021-06-17 Thread Ayush Bisht

class Year(models.Model):
year = models.IntegerField()


class Month(models.Model):
MONTH_CHOICE = (
(1 , "Jan"),
(2, 'Feb'),
(3, 'March'),
(4, 'April'),
(5, 'May'),
(6, 'June'),
(7, 'July'),
(8, 'Aug'),
(9, 'Sept'),
(10, 'Oct'),
(11, 'Nov'),
(12, 'Dec')

)
month = models.PositiveSmallIntegerField(choices = MONTH_CHOICE)
year = models.ForeignKey(Year, on_delete= models.SET_NULL)


class Student(models.Model):
name = models.CharField(max_length=266)
admission_month = models.ForeignKey(Month, on_delete=models.SET_NULL)


you can proceed with this approach also... 

On Wednesday, June 16, 2021 at 2:37:34 PM UTC-7 adesolar...@gmail.com wrote:

> Good day,
> Please how can this be achieved?
> Best regards.
>
> On Wed, Jun 16, 2021, 7:01 PM Ridwan Adeyemo  
> wrote:
>
>> Thanks man.
>>
>> On Wed, Jun 16, 2021, 5:22 PM Ayush Bisht  wrote:
>>
>>> I think you are trying to sum up the value of two model fields and store 
>>> them in some other field. 
>>>
>>>
>>> so for that u can proceed from base. 
>>>
>>> simple you just have to update that field in save method
>>>
>>> for example : 
>>>  *class Student(models.Model):*
>>>maths_score = models.DecimalField()
>>>english_score = models.DecimalFIeld()
>>>Total_score   = models.DecimalField(default = 0)
>>>
>>>*def save(self, *args, **kwargs):*
>>> *  self.Total_score  = self.maths_score  + self.english_score*
>>>   super(Student, self).save(*args, **kwargs)
>>>
>>>
>>>
>>> or you can proceed with clean() method also. 
>>> On Tuesday, June 15, 2021 at 11:34:37 AM UTC-7 adesolar...@gmail.com 
>>> wrote:
>>>
>>>> How do I add two models together in the database, two different 
>>>> DecimalField. 
>>>> i.e math_score + eng_score = total_score
>>>>
>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/django-users/qsaj_ELIfgA/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> django-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/81d7b7b1-9521-47b1-9fef-91be3ba4c952n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/81d7b7b1-9521-47b1-9fef-91be3ba4c952n%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>

-- 
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/41290c5b-17f5-4be5-94a2-5ba9db079b02n%40googlegroups.com.


Re: How to use django template tags in .js file ??

2021-06-17 Thread Ayush Bisht
thanks, It works for me  

On Wednesday, June 16, 2021 at 12:08:20 PM UTC-7 Nikeet NA wrote:

> Or you can store the url in the variable then use it.
>
> On Thursday, 17 June 2021 at 00:29:00 UTC+5:30 Nikeet NA wrote:
>
>> Do like this use 
>> var obj_slug = object.slug inside script tag below it include your js 
>> file with the above js script. in js file you can acces it with obj_slug 
>> variable.
>>
>> On Wednesday, 16 June 2021 at 22:31:39 UTC+5:30 kuassi...@paydunya.com 
>> wrote:
>>
>>> I also had the problem once. But what I understood is that the 
>>> interpretation of the DJANGO syntax in statics files only works when the 
>>> file has an HTML extension. So if you really want to do something separate 
>>> with the script you can just create another HTML file but in another folder 
>>> where you will put the script content surrounded by the SCRIPT tags and 
>>> then you will just include with the directive {% INCLUDE %} in 
>>> your main HTML file.
>>>
>>> On Wednesday, June 16, 2021 at 3:59:16 PM UTC bisht.a...@gmail.com 
>>> wrote:
>>>
 while doing great stuff with django I have found some clumsy behaviour 
 of django in handling .js file. Is there a way to effectively integrate 
 all 
 the stuff of   in a separate file and effectively used it 
 with rest of the html code. 

 for example : 

 // *file.html 
 ..*

 
   

 >>> method="POST" id="likes-form">
 {% csrf_token %}

 >>> id="like-{{
 object.pk}}">
 
   
   
 {{ object.total_likes }}
   
 




 //  *file.js file*  
 ..

 $("#likes-form").submit(function (e)
 {  e.preventDefault();
   var serializedData = $(this).serializeArray();
   $.ajax({
   type: 'POST',
   url: '{% url 'blog_likes' object.slug  %}',
   data: serializedData,
   success: function (response) {
 var like_count = JSON.parse(response["like"]);
 like_flag = JSON.parse(response["flag"]);
 
 console.log(like_flag);
   
 if(like_flag == 0){  
 $(".like-inner-flex-1").toggleClass('like-animate');   
   }else
   $(".like-inner-flex-1").toggleClass('like-animate'); 
   
   if(like_flag){

   $('.like-btn').css({"background-color": "#d629801a" , "outline": 
 "none"});

 $('.like-inner-flex-1').css({"background-position": "right",  
 "filter": "grayscale(0%)"});

 } else {

 $('.like-btn').css({"background-color": "transparent", "outline": 
 "none"});

 $('.like-inner-flex-1').css({"background-position": "right",  
 "filter": "grayscale(100%)"});

 }

 $("#likes").text(`${like_count}`);
 }})
 })

 ..

 if I use above script inside the same html file then it works, but in 
 above case its not working ?? If there is any work around to do this thing 
 , then please suggest me .

 Thank you...

  




-- 
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/0e2ac9d2-60ef-4acf-b69f-8f0ba70eeffbn%40googlegroups.com.


Re: Adding Two Models In Django

2021-06-16 Thread Ayush Bisht
I think you are trying to sum up the value of two model fields and store 
them in some other field. 


so for that u can proceed from base. 

simple you just have to update that field in save method

for example : 
 *class Student(models.Model):*
   maths_score = models.DecimalField()
   english_score = models.DecimalFIeld()
   Total_score   = models.DecimalField(default = 0)

   *def save(self, *args, **kwargs):*
*  self.Total_score  = self.maths_score  + self.english_score*
  super(Student, self).save(*args, **kwargs)



or you can proceed with clean() method also. 
On Tuesday, June 15, 2021 at 11:34:37 AM UTC-7 adesolar...@gmail.com wrote:

> How do I add two models together in the database, two different 
> DecimalField. 
> i.e math_score + eng_score = total_score
>

-- 
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/81d7b7b1-9521-47b1-9fef-91be3ba4c952n%40googlegroups.com.


How to use django template tags in .js file ??

2021-06-16 Thread Ayush Bisht
while doing great stuff with django I have found some clumsy behaviour of 
django in handling .js file. Is there a way to effectively integrate all 
the stuff of   in a separate file and effectively used it 
with rest of the html code. 

for example : 

// *file.html 
..*


  

{% csrf_token %}


  
  
{{ object.total_likes }}
  





//  *file.js file*  
..

$("#likes-form").submit(function (e)
{  e.preventDefault();
  var serializedData = $(this).serializeArray();
  $.ajax({
  type: 'POST',
  url: '{% url 'blog_likes' object.slug  %}',
  data: serializedData,
  success: function (response) {
var like_count = JSON.parse(response["like"]);
like_flag = JSON.parse(response["flag"]);

console.log(like_flag);
  
if(like_flag == 0){  
$(".like-inner-flex-1").toggleClass('like-animate');   
  }else
  $(".like-inner-flex-1").toggleClass('like-animate'); 
  
  if(like_flag){
  $('.like-btn').css({"background-color": "#d629801a" , "outline": 
"none"});
$('.like-inner-flex-1').css({"background-position": "right",  "filter": 
"grayscale(0%)"});

} else {
$('.like-btn').css({"background-color": "transparent", "outline": 
"none"});
$('.like-inner-flex-1').css({"background-position": "right",  "filter": 
"grayscale(100%)"});

}

$("#likes").text(`${like_count}`);
}})
})

..

if I use above script inside the same html file then it works, but in above 
case its not working ?? If there is any work around to do this thing , then 
please suggest me .

Thank you...

 


-- 
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/fbb6ae3c-2632-4183-9336-fb6bad5dfe0en%40googlegroups.com.


Re: Inlined hierarchy models in django admin site.

2021-06-01 Thread Ayush Bisht
thanks, .. it works for me.. but is there any other way to do these ??. as 
PatientVaccineStatus already connected to Patient model, and Vaccine 
connected to PatientVaccineStatus model.  Can't we merged all the tables of 
descendants to their parent model in this hierarchy fashion without linking 
each descendants to its.. super parent?? 


On Tuesday, June 1, 2021 at 1:31:43 AM UTC-7 abubak...@gmail.com wrote:

> class Vaccine(models.Model)
>  vaccine = models.ForeignKey(PatientVaccineStatus, 
> related_name="vaccine_status")
> patient = models.ForeignKey(Patient, related_name="patient")  # new 
> line
> apply this line and your patient model will be linked with Vaccine model 
>
> On Tue, Jun 1, 2021 at 11:06 AM Ayush Bisht  wrote:
>
>> class Patient(models.Model):
>>  patient_id = models.CharField(max_length=60)
>>
>>
>> class PatientVaccineStatus(models.Model):
>>   patient = models.ForeignKey(Patient, 
>> related_name="patient_vaccine_status")
>>
>> class Vaccine(models.Model)
>>  vaccine = models.ForeignKey(PatientVaccineStatus, 
>> related_name="vaccine_status")
>>  
>> ..
>>
>> Is there any way to merged all the tables in a single table of patient.
>>
>> I successfully merge, PatientVaccineStatus table with Patient table, but 
>> Vaccine's table is not merging with the Patient. 
>>
>> how can this hierarchy be merged in a single table.
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/1d1dfc11-b044-4474-9f62-2b25b9c5f9d9n%40googlegroups.com.


Re: Inlined hierarchy models in django admin site.

2021-06-01 Thread Ayush Bisht
yes, its true, but here it works as candidate key. so that we can identify 
the patient based in ICMR id's. 

On Tuesday, June 1, 2021 at 1:34:24 AM UTC-7 abubak...@gmail.com wrote:

> class Patient(models.Model):
>  patient_id = models.CharField(max_length=60) # no need for adding 
> patient id because django automatically creates ids
> patient_vaccine = models.ForeignKey(PatientVaccine, 
> related_name="patient_vaccine")
>vaccine = models.ForeignKey(Vaccinet, related_name="vaccinet")
>
> On Tue, Jun 1, 2021 at 1:30 PM DJANGO DEVELOPER  
> wrote:
>
>> class Vaccine(models.Model)
>>  vaccine = models.ForeignKey(PatientVaccineStatus, 
>> related_name="vaccine_status")
>> patient = models.ForeignKey(Patient, related_name="patient")  # new 
>> line
>> apply this line and your patient model will be linked with Vaccine model 
>>
>> On Tue, Jun 1, 2021 at 11:06 AM Ayush Bisht  wrote:
>>
>>> class Patient(models.Model):
>>>  patient_id = models.CharField(max_length=60)
>>>
>>>
>>> class PatientVaccineStatus(models.Model):
>>>   patient = models.ForeignKey(Patient, 
>>> related_name="patient_vaccine_status")
>>>
>>> class Vaccine(models.Model)
>>>  vaccine = models.ForeignKey(PatientVaccineStatus, 
>>> related_name="vaccine_status")
>>>  
>>> ..
>>>
>>> Is there any way to merged all the tables in a single table of patient.
>>>
>>> I successfully merge, PatientVaccineStatus table with Patient table, but 
>>> Vaccine's table is not merging with the Patient. 
>>>
>>> how can this hierarchy be merged in a single table.
>>>
>>> -- 
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>

-- 
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/d7ca06cb-c662-4994-b8cd-ff0cbfd61ea8n%40googlegroups.com.


Inlined hierarchy models in django admin site.

2021-06-01 Thread Ayush Bisht
class Patient(models.Model):
 patient_id = models.CharField(max_length=60)


class PatientVaccineStatus(models.Model):
  patient = models.ForeignKey(Patient, 
related_name="patient_vaccine_status")

class Vaccine(models.Model)
 vaccine = models.ForeignKey(PatientVaccineStatus, 
related_name="vaccine_status")
 
..

Is there any way to merged all the tables in a single table of patient.

I successfully merge, PatientVaccineStatus table with Patient table, but 
Vaccine's table is not merging with the Patient. 

how can this hierarchy be merged in a single table.

-- 
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/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com.


Custom Text filter field in django admin site.

2021-05-31 Thread Ayush Bisht
# admin.py

class InputFilter(admin.SimpleListFilter):
template = 'patient/input_filter.html'

def lookups(self, request, model_admin):
# Dummy, required to show the filter.
return ((),)

class PatientProfilePastDataFilter(InputFilter):
parameter_name = 'patient'
title = _('Past Record')

def lookups(self, request, model_admin):
return ( (),)

def queryset(self, request, queryset):   
return queryset.filter(admitted_on__lte = request.GET.get("from") , 
admitted_on__gte  
 = request.GET.get("to")  )

# patient/input_filter.html
{% load i18n %} 

{% blocktrans with filter_title=title %} By {{ filter_title }} {% 
endblocktrans %}


{% with choices.0 as all_choice %}








filter
{% if not all_choice.selected %}
x {% trans 
'Remove' %}
{% endif %}


{% endwith %}



 # 
.


I want to add a custom text filter in django admin site... with 2 input 
fields. Is there a way to do this.. if so then please suggest me,  how can 
I add a custom text field in filter section.

Also, Thanks for the  respond on previous query... 

-- 
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/2dc28aa3-90d0-422f-8d9c-4b5f5b6fb7f6n%40googlegroups.com.


Validate UserChangeForm from admin site

2021-05-11 Thread Ayush Bisht
# admin.py
class CustomUserAdmin(UserAdmin):
model = CustomUser
add_form = CustomUserCreationForm
fieldsets = (

*UserAdmin.fieldsets, (
'User type',{
'fields' : (
'is_admin',
'is_doctor',
'is_nurse',

),
'description': "Select any one of them "
}
)
)

# models.py

class CustomUser(AbstractUser):
username = models.CharField(max_length=50, unique=True, blank=False, 
null=False)   
is_doctor = models.BooleanField(default=False, blank=False, null=False)
is_nurse = models.BooleanField(default=False, blank=False, null=False)  
  
is_admin = models.BooleanField(default=False, blank=False, null=False)


# forms.py

class CustomUserCreationForm(forms.ModelForm):
"""
A form that creates a user, with no privileges, from the given username and
password.
"""
error_messages = {
'password_mismatch': _('The two password fields didn’t match.'),
}
password1 = forms.CharField(
label=_("Password"),
strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
# help_text=password_validation.password_validators_help_text_html(),
)
password2 = forms.CharField(
label=_("Password confirmation"),
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
strip=False,
help_text=_("Enter the same password as before, for verification."),
)
 
class Meta:
model = CustomUser
# fields = "('username',  'password' ,'password2', 'userchoice')"
fields = ("username",)
# field_classes = {'username': UsernameField}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) 
self.fields['username'].help_text = 'Enter you Staff ID'


def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise ValidationError(
self.error_messages['password_mismatch'],
code='password_mismatch',
)
return password2


def save(self, commit=True):
user = super().save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user



..

the is_doctor , is_nurse   and is_admin fields comes at the userchageform.. 
is there a way to validate the fields at admin level.  I mean if someone , 
checked more than one designation then , a field error have to appear on 
the admin userchangeform,   Is there any way to customize the 
userchangeform...

Any help would be highly appreciable , 


-- 
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/da01a016-26fc-4590-992d-eaf86a502d7an%40googlegroups.com.