Re: Novice questions about Pagination syntax and classes in general

2019-06-01 Thread John Bagiliko
I will answer question two. I'm not sure I understand your question 1. The
"objects" is query method of every Django model. You use it to query.
Contacts should be in your models.py and you should import  Contacts in
your views.py before you can use it.

On Sun, Jun 2, 2019, 1:08 AM drone4four  wrote:

> As part of the official Django doc on Pagination
> ,
> take a look at the listing function:
>
> def listing(request):
> contact_list = Contacts.objects.all()
> paginator = Paginator(contact_list, 25) # Show 25 contacts per page
>
>
> My two questions are:
>
>1.
>
>Is it possible to return more than one value when a function is
>assigned to a variable, like at line 3?
>2.
>
>At line 2, is `objects` a method within the Contacts class? If so,
>where is the Contacts class defined? It’s not imported at the top of the
>example views.py also in that Django doc above where I got this code 
> sample.
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3540a14b-ef8a-4de3-ad59-858ca1c2a7c4%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC26BE3NXuvsfiOiyF_OAdUXB%3D2nX5S9xEb_OT-8_2v5Zx1cBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Atomic IntegerField increment based on another model instance

2019-06-01 Thread Ryan Causey
Assume the following models for this question:

class Jurisdiction(models.Model):
name = models.CharField(max_length = 100)

class Account(models.Model):
account_number = models.PositiveIntegerField(blank = True)
jurisdiction = models.ForeignKey("Jurisdiction", on_delete = models.
CASCADE)

class Meta:
"""Meta model to define unique_together constraints."""
#make the account_number unique for a jurisdiction
unique_together = ("account_number", "jurisdiction")

def create_account_number(self):
"""Create the account number for this account."""
# If the account number is already set, do nothing.
if self.account_number is not None:
return

# Get the last account created for the jurisdiction, based on 
having the largest account number.
last_account_for_jurisdiction = Account.objects.filter(jurisdiction 
= self.jurisdiction).order_by("-account_number").first()
# If the account exists set the account number.
if last_account_for_jurisdiction is not None:
self.account_number = last_account_for_jurisdiction.account_number 
+ 1
# Else there are no other accounts for this jurisdiction, set the 
first account number.
else:
self.account_number = 1

def save(self, *args, **kwargs):
# create the account number
self.create_account_number()
# call the superclass save to write the account to the database.
super().save(*args, **kwargs)

Is there a way in Django to be able to atomically set account_number on 
save based on the largest account number for a given jurisdiction? I was 
hoping some combination of F expressions 
, 
conditional expressions 
, 
and subquery expressions 
 would allow 
me to do this, but they don't appear to allow referencing a different 
model's fields.

The unique_together will properly prevent duplicate Jurisdiction + 
account_number pairs from being entered into the DB, but I was hoping there 
was a way to perform the setting of account_number in an atomic way so I 
wouldn't have to handle an IntegrityError and try again. I get the feeling 
what I'm asking for isn't possible, or there's a completely different way I 
should be going about this. I haven't used AutoField as I need a sequental 
series of numbers within each Jurisdiction.

Thanks in advance for the help.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fc7a0001-a576-46e5-b0a1-aeec500ad77c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Novice questions about Pagination syntax and classes in general

2019-06-01 Thread drone4four


As part of the official Django doc on Pagination 
,
 
take a look at the listing function:

def listing(request):
contact_list = Contacts.objects.all()
paginator = Paginator(contact_list, 25) # Show 25 contacts per page


My two questions are:

   1. 
   
   Is it possible to return more than one value when a function is assigned 
   to a variable, like at line 3? 
   2. 
   
   At line 2, is `objects` a method within the Contacts class? If so, where 
   is the Contacts class defined? It’s not imported at the top of the example 
   views.py also in that Django doc above where I got this code sample.
   

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3540a14b-ef8a-4de3-ad59-858ca1c2a7c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: is that any way to deploy django in apache with centos

2019-06-01 Thread Ryan Nowakowski
Please post the specific error you're getting.

On May 30, 2019 6:59:22 AM CDT, Kurosh Sol  wrote:
>is that any way to set Django in apache with wsgi mod  in centos
>I keep reading and still get error 
>any good resource can really work?
>
>-- 
>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 post to this group, send email to django-users@googlegroups.com.
>Visit this group at https://groups.google.com/group/django-users.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/django-users/d041c339-201f-420b-a2b1-849016ae0b7a%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ED256938-23CE-467B-A2B7-91F64A9D7425%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.


Re: Collectstable displays 0 static file copied issue

2019-06-01 Thread Chetan Ganji
I use below settings. For this to work you have to create 2 folders inside
the folder where manage.py is located - "*static*" and "*media*".
Use below settings and run the *collectstatic* command once again and see
if it works for you.


STATIC_URL = '/static/'
MEDIA_URL = '/media/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]

STATIC_ROOT = os.path.join(BASE_DIR, "static/")
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Sat, Jun 1, 2019 at 4:54 PM Ankhi Roy  wrote:

> Hey,
>
>
> So I have made the following changes and Django can now read static CSS
> file now there is no more 404 while loading the static css file. However,
> on the web browser, the output does not reflect css properties like header
> color or header alignment.
>
> I have run python3 manage.py collectstatic(since i am using python3) got
> the following output -
>
> "0 static files copied to
> '/home/username/project/file:/home/username/project/app/templates/static',
> 120 unmodified." -- Not sure what this means, does it means Django is still
> unable to fetch the CSS static file? I am guessing this as I still cannot
> see any CSS specific change on my view. I would like to confirm the cause.
>
> I am using ubuntu linux 18.04, Django-admin - 2.2.1 and Pycharm Community
> IDE.
>
> so my settings.py file has -
>
> STATIC_ROOT = 'file:///home/username/project/app/templates/static/'
> STATIC_URL = 'file:///home/username/project/app/templates/static/'
> BASE_DIR1 = '/home/username/project/app/templates/'
> STATICFILES_DIRS = [
>
> os.path.join(BASE_DIR1, 'static'),
>
> ]
>
> My app/View.py file -
>
> 
> 
> {%load static%}
>  "text/css">
>  #Inline css is working the problem is while loading
> external css file by Django.
> 
> 
>  Hello World!!!
> 
> 
>
>
> My External index.css file -
>
> h1 {
> color: blue;
> text-align: center;
> }
>
> Please help and guide.
>
> Thanks
>
> Ankhi
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b5216c4a-81a6-4d7f-a890-ad8faf7d840d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjs%3D5GtV3DnMN%3DXJm2dB_%2B3NTgubqjPFfva6Hjx2%2B8RU-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error while doing django tutorial part 2

2019-06-01 Thread rf
on last line your code is: 
return self.question_text
it should be:
return self.choice_text

On Monday, September 10, 2018 at 3:17:08 AM UTC+4:30, Pravinkumar Kale 
wrote:
>
>
> I am also getting same issue...
> Following is my code
>
> ##
> from django.db import models
> from django.utils import timezone
>
> class Question(models.Model):
> question_text = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
> def __str__(self):
> return self.question_text
> def was_published_recently(self):
> return self.pub_date>=timezone.now()
> 
>
>
> class Choice(models.Model):
> question = models.ForeignKey(Question, on_delete=models.CASCADE)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField(default=0)
> def __str__(self):
> return self.question_text
> #
>
>
> On Sunday, May 27, 2018 at 11:51:39 AM UTC+5:30, TonyF-UK wrote:
>>
>> What is the code for your Choice model.  The error message clearly states 
>> that the Choice model is the one with the problem. 
>>
>> -- 
>> Anthony Flury
>> email : anthon...@btinternet.com
>> Twitter : @TonyFlury
>>
>> On 26 May 2018, at 18:47, Kranthi Kiran <1991.k...@gmail.com> wrote:
>>
>> Text of error message in case the image is not loading
>>
>>
>> >>> q = Question.objects.get(pk=1)
>> >>> q.choice_set.all()
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "/usr/lib64/python3.6/site-packages/django/db/models/query.py", 
>> line 251,  
>> in __repr__
>> return '<%s %r>' % (self.__class__.__name__, data)
>>   File "/usr/lib64/python3.6/site-packages/django/db/models/base.py", 
>> line 513,  
>> in __repr__
>> return '<%s: %s>' % (self.__class__.__name__, self)
>>   File "/home/kkondapalli/mysite/polls/models.py", line 25, in __str__
>> return self.question_text
>> AttributeError: 'Choice' object has no attribute 'question_text'
>> >>>
>>
>>
>>
>> On Saturday, 26 May 2018 22:49:04 UTC+5:30, Kranthi Kiran wrote:
>>>
>>> Hello User,
>>>
>>> I am following django tutorial at 
>>> https://docs.djangoproject.com/en/2.0/intro/tutorial02/
>>>
>>> After modifying polls/models.py  and when running python3.6 manage.py 
>>> shell again
>>>
>>>
>>> I am getting the following error at the following 
>>>
>>> >>> q = Question.objects.get(pk=1)
>>> # Display any choices from the related object set -- none so far.>>> 
>>> q.choice_set.all()
>>>
>>>
>>> Error screenshot
>>>
>>>
>>>
>>>
>>> Please help me to resolve the issue at earliest
>>>
>> -- 
>> 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 post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/0e27456c-eefa-4a1e-bf4f-a44d9e8dcad1%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5a9d0ea-4cd1-4f42-874d-690719c43d1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


password reset

2019-06-01 Thread ExplaineR KhaN
​ i handle password reset 
when i write this code can not me send email 
def send_mail(to, template, context): 
html_content = render_to_string(f'accounts/emails/{template}.html', 
context) 
text_content = render_to_string(f'accounts/emails/{template}.txt', context) 
msg = EmailMultiAlternatives(context['subject'], text_content, 
settings.EMAIL_HOST_USER, [to]) 
msg.attach_alternative(html_content, 'text/html') 
msg.send()

when i write like this 
send me email how to achieve dynamically
def send_mail(to, template, context): 
html_content = render_to_string(f'accounts/emails/{template}.html', 
context) 
text_content = render_to_string(f'accounts/emails/{template}.txt', context) 
msg = EmailMultiAlternatives(context['subject'], text_content, 
settings.EMAIL_HOST_USER, ['inayatullahk.kh...@gmail.com']) 
msg.attach_alternative(html_content, 'text/html') 
msg.send() 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad856393-c348-405c-8126-6952dda54791%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Collectstable displays 0 static file copied issue

2019-06-01 Thread Ankhi Roy
Hey,


So I have made the following changes and Django can now read static CSS 
file now there is no more 404 while loading the static css file. However, 
on the web browser, the output does not reflect css properties like header 
color or header alignment.

I have run python3 manage.py collectstatic(since i am using python3) got 
the following output - 

"0 static files copied to 
'/home/username/project/file:/home/username/project/app/templates/static', 
120 unmodified." -- Not sure what this means, does it means Django is still 
unable to fetch the CSS static file? I am guessing this as I still cannot 
see any CSS specific change on my view. I would like to confirm the cause.

I am using ubuntu linux 18.04, Django-admin - 2.2.1 and Pycharm Community 
IDE.

so my settings.py file has -

STATIC_ROOT = 'file:///home/username/project/app/templates/static/'
STATIC_URL = 'file:///home/username/project/app/templates/static/'
BASE_DIR1 = '/home/username/project/app/templates/'
STATICFILES_DIRS = [

os.path.join(BASE_DIR1, 'static'),

]

My app/View.py file -



{%load static%}

 #Inline css is working the problem is while loading 
external css file by Django.


 Hello World!!!




My External index.css file - 

h1 {
color: blue;
text-align: center;
}

Please help and guide.

Thanks

Ankhi

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5216c4a-81a6-4d7f-a890-ad8faf7d840d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Possible bug [Was: jquery deployment]

2019-06-01 Thread Mike Dewhirst

On 31/05/2019 6:04 pm, Mike Dewhirst wrote:

On 30/05/2019 8:22 pm, Mike Dewhirst wrote:
I just encountered a weird UI glitch[1] in the Admin after upgrading 
to Django 2.2.1






I have now discovered the problem described earlier is more generic as 
follows:


1. For *any *ForeignKey or ManyToManyField in the Admin, if you click 
(SHOW) and there is already an existing related record it will open up 
nicely. No sign of any bug.


2. For any such related item if you "Add another " and click 
(SHOW) the Admin will reposition to the top of the page instead of 
opening the collapsed fields.


3. I have disabled all my own css

4. There is no js in any of my static dirs - relying entirely on 
Django's js.


5. I haven't changed the Admin fieldsets 'classes': ('collapse',),

6. The problem goes away if I downgrade to Django 2.1.8


Back in 2.2.1 ...

7. Results are identical in both Chrome and Firefox

8. Commenting out lines 48, 49 and 50 in 
contrib/admin/static/admin/js/collapse.js [2] causes the same problem 
for 1 above.  I really don't know javascript but it seems to me 
toggleFunc isn't toggling Hide / Show correctly *when there is an 
unsaved empty related record*. See toggleFunc from collapse.js [3]


[2]

48    for (i = 0; i < toggles.length; i++) {

49    toggles[i].addEventListener('click', toggleFunc);

50    }

( I did try line 48 as ... for (var i = 0; i < toggles.length; i++) { 
... but no cigar)


[3]

33    // Add toggle to anchor tag

34    var toggles = document.querySelectorAll('fieldset.collapse 
a.collapse-toggle');

35    var toggleFunc = function(ev) {

36    ev.preventDefault();

37    var fieldset = closestElem(this, 'fieldset');

38    if (fieldset.classList.contains('collapsed')) {

39    // Show

40    this.textContent = gettext('Hide');

41    fieldset.classList.remove('collapsed');

42    } else {

43    // Hide

44    this.textContent = gettext('Show');

45    fieldset.classList.add('collapsed');

46    }

47    };


Should I start a new project and try and demonstrate it there?

Thanks

Mike





What code would be interesting in this case?

Any hints?

Thanks

Mike



Is there a best practice for ensuring I keep my projects up to date?

Thanks

Mike

[1] With a m2m (self) adding another instance clicking on the {SHOW} 
link just relocates to the top of the page. Has to be a jQuery thing 
doesn't it?




--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/daa13769-bbf0-4ca9-cf5d-b094ce4aa640%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: advantage of angular js with django??

2019-06-01 Thread Nick Sarbicki
> The biggest advantage is you can create, change or have multiple frontend
systems on different platforms without having to make changes to your
Django backend. For example you can create an AngularJS web app and a React
Native app for iOS using the same Django backend.

It's worth noting that this is an advantage of having a full fledged API
and not an advantage of using angular.

On Fri, 31 May 2019, 16:59 Joe Reitman,  wrote:

> AngularJS is a Single Page App (SPA) framework. You can use Django along
> with Django Rest API package as the backend to your Angular app. The
> biggest advantage is you can create, change or have multiple frontend
> systems on different platforms without having to make changes to your
> Django backend. For example you can create an AngularJS web app and a React
> Native app for iOS using the same Django backend.
>
> On Friday, May 31, 2019 at 2:43:25 AM UTC-5, Pradeep Singh wrote:
>>
>> What are the advantages of using AngularJS with Django?
>>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/eb63d6f5-5125-4e5f-882d-eaa469529323%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGuvt92ecrrMdz_0Pp9A2LsNDwmCT_XcjK5wacyMPz3CcX1frA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.