Re: Absolute beginner step by step

2016-06-15 Thread M. Kholid
I tried to downloan the tutorial from the given link /
media.readthedocs.org/pdf/tango-with-django/latest/tango-with-django.pdf

It stil using django version 1.5.4

On Wed, Jun 15, 2016 at 10:44 PM, Shaylee Hansen <
shan...@gcommercesolutions.com> wrote:

> Thanks for the update on the new Tango With Django.   Everyone highly
> recommends this tutorial so I'm excited to see its recently been updated :)
>
> On Monday, June 13, 2016 at 12:51:07 PM UTC-6, gary719_list1 wrote:
>>
>> I stand corrected. There is a new Tango With Django tutorial out. It uses
>> Python 3.5 and Django 1.9. Try /
>> media.readthedocs.org/pdf/tango-with-django/latest/tango-with-django.pdf
>>
>> Gary R
>>
>> On 06/11/2016 02:07 PM, Gary Roach wrote:
>>
>> If you don't mind working with Python2.7 and Django 1.7 you might try
>> "Tango With Django" . It is out of date but still is a good place to start.
>> Too bad that the author hasn't updated it. I have had some success with
>> running three projects in parallel. Tango along with the official Django
>> howto and another with your own project if you have one. I saw a reference
>> to "Learning Python The  Hard Way". It's a good choice.
>>
>> One nasty thing you may run into if you run parallel programs is the use
>> of multiple version of Python and Django. If you use virtualenv and pyvenv
>> to set up multiple virtual environments and then point your IDE at the one
>> needed for a particular project, you should be ok. You don't even have to
>> activate the environments because you are using them for storage of python
>> and django versions only.
>>
>> Good luck
>>
>> Gary R.
>>
>>
>> On 06/10/2016 07:32 PM, Mc. Holid wrote:
>>
>> Dear All,
>>
>> Could anyone help  to share the point for absolute beginner guide.
>>
>> I have already know a little bit about html, and having strong background
>> in vb6.
>>
>> Thanks for any kind help.
>>
>> Best Regards
>> Mchoud
>> --
>> 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/d2fa7fd5-2673-4292-a14e-482e148587bb%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...@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/575C7D80.7060206%40verizon.net
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
> NOTICE: This email and attached file(s) contain Gcommerce Solutions, LLC
> confidential information intended for the exclusive use of the
> individual(s) to whom addressed. If you are not the intended recipient,
> please immediately delete this Email (and attached files) and treat the
> information as confidential.
>
> --
> 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/cryoIzZ7p-o/unsubscribe.
> To unsubscribe from this group and all its topics, 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/b4c64c46-02a6-4237-bbff-b4b3fbd0d6e8%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/CADEwvuwPPzPTFLnGODT2sTFj7EYBwS6bFxH_b9UYz3m8FZy5mQ%40mail.gmail.com.
For more options, 

Re: how to use view function in another function of view in django

2016-06-15 Thread hossein
More Explain Please

On Thursday, June 16, 2016 at 3:13:38 AM UTC+4:30, Gergely Polonkai wrote:
>
> Just like this. Unless you have a specific use case you forgot to share in 
> your mail.
>
> Views are mere functions that get called with a request az a parameter. 
> You shouldn’t treat them as special/holy/uncallable.
>
> Best,
> Gergely
> On Jun 15, 2016 19:56, "hossein"  wrote:
>
>> def base(request):
>> j=Job.objects.all()
>> a=Ab.objects.all()
>> return render(request,'base.html',{'j':j, 'a':a})
>>
>> def index(request):
>> base(request)
>> x=X.objects.all()
>> return render(request, 'index.html',{'x':x})
>>
>> def list(request):
>> base(request)
>> z=Z.objects.all()
>> return render(request, 'list.html',{'z':z})
>>
>> -- 
>> 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/3cc2651c-35df-4eaf-bab6-b1ae936f73d4%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/72d16e93-10b7-4465-b116-68bf054a89d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: LoginRequiredMixin ignored

2016-06-15 Thread Brian Schott
Try swapping class order.

Sent from my iPhone

> On Jun 15, 2016, at 6:55 PM, Lee Hinde  wrote:
> 
> Using Django 1.9.7.
> I have the following class:
> class AddView(LoginRequiredMixin, CreateView):
> template_name = "entry.html"
> model = Property
> form_class = AddPropertyForm
> success_url = "/buy/"
> login_url = '/account/login/'
> 
> def dispatch(self, request, *args, **kwargs):
> print request.user
> print request.user.is_authenticated()
> return super(AddView, self).post(request, *args, **kwargs)
> 
> def form_valid(self, form):
> ls_property = form.save(commit=False)
> ls_property.user = get_user(self.request)
> ls_property.latitude = form.cleaned_data['latitude']
> ls_property.longitude = form.cleaned_data['longitude']
> submit =  form.cleaned_data['submit']
> ls_property.visible = (submit != 'draft')
> ls_property.save()
> return super(AddView, self).form_valid(form)
> 
> The LoginRequiredMixin is ignored, i.e, I can get to the page without being 
> logged in.
> request.user reports: AnonymousUser
> request.user.is_authenticated() reports: False
> If I wrap the url:
> url(r'^sell', user_passes_test(user_is_active)(AddView.as_view()), 
> name="add"),
> the page is protected, so I have a work around.
> This seems basic and I don't find other reports of LoginRequiredMixin not 
> working, so I assume it's me.
> What am I missing?
> 
> 
> 
> -- 
> 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/CA%2BePoMzApQGdzZ9AW47CjF3yhT0Smnc1AZw%2BOQ8uTcH1G3%3Dasg%40mail.gmail.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/C45F29DE-EF15-4890-B73D-A7B20627CE5D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


LoginRequiredMixin ignored

2016-06-15 Thread Lee Hinde
Using Django 1.9.7.

I have the following class:

class AddView(LoginRequiredMixin, CreateView):
template_name = "entry.html"
model = Property
form_class = AddPropertyForm
success_url = "/buy/"
login_url = '/account/login/'

def dispatch(self, request, *args, **kwargs):
print request.user
print request.user.is_authenticated()
return super(AddView, self).post(request, *args, **kwargs)

def form_valid(self, form):
ls_property = form.save(commit=False)
ls_property.user = get_user(self.request)
ls_property.latitude = form.cleaned_data['latitude']
ls_property.longitude = form.cleaned_data['longitude']
submit =  form.cleaned_data['submit']
ls_property.visible = (submit != 'draft')
ls_property.save()
return super(AddView, self).form_valid(form)


The LoginRequiredMixin is ignored, i.e, I can get to the page without
being logged in.

request.user reports: AnonymousUserrequest.user.is_authenticated()
reports: False

If I wrap the url:

url(r'^sell', user_passes_test(user_is_active)(AddView.as_view()), name="add"),

the page is protected, so I have a work around.

This seems basic and I don't find other reports of LoginRequiredMixin
not working, so I assume it's me.

What am I missing?

-- 
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/CA%2BePoMzApQGdzZ9AW47CjF3yhT0Smnc1AZw%2BOQ8uTcH1G3%3Dasg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to use view function in another function of view in django

2016-06-15 Thread Gergely Polonkai
Just like this. Unless you have a specific use case you forgot to share in
your mail.

Views are mere functions that get called with a request az a parameter. You
shouldn’t treat them as special/holy/uncallable.

Best,
Gergely
On Jun 15, 2016 19:56, "hossein"  wrote:

> def base(request):
> j=Job.objects.all()
> a=Ab.objects.all()
> return render(request,'base.html',{'j':j, 'a':a})
>
> def index(request):
> base(request)
> x=X.objects.all()
> return render(request, 'index.html',{'x':x})
>
> def list(request):
> base(request)
> z=Z.objects.all()
> return render(request, 'list.html',{'z':z})
>
> --
> 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/3cc2651c-35df-4eaf-bab6-b1ae936f73d4%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/CACczBULw3kggNH5%3DerHjm5iY6yFkjwEknLL8V9Cpa1N9RX2Cww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Dynamic code analyzer for Django

2016-06-15 Thread Raúl Quesada Pegalajar
Hello!!

We have a big Django application in production since a few years. We want 
to refactor it, but before that, we want to study the real status about our 
code. We want to do static and dynamics analisys to discover: Errors, 
duplicities, dead code, unused features...

We have found some tools for static analysis, but we can not find a good 
tool for a dynamic analsys. We want to discover what pieces of our 
application are not being used by our clients and remove it.

Do you know any tool to do this kind of analysis?

Thanks in advance,

-- 
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/4dcd6f0c-39f9-4608-9aa9-3450cb1c47ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Recommended courses/materials for Python/Django course...

2016-06-15 Thread Fred Stluka

  
  
Python/Django users,

Any Python and/or Django courses/materials to recommend?

I may be teaching a Python/Django class soon.  My client may be 
willing to jumpstart by buying existing course materials (lecture 
slides, notes, homeworks, labs, reference links, any other
materials).
We'll certainly be happy to make use of any free materials.

Do you have any Python and/or Django courses/materials to 
recommend?

I've taken a quick look and found:
- Main web sites:
  - http://python.org
  - https://djangoproject.com (excellent docs and tutorial!)
- Free courses:
  - https://developers.google.com/edu/python
- Free/paid courses:
  - http://learnpythonthehardway.org/book
- Books
  - 2 Scoops of Django
- Paid courses:
  - Coursera
  - Codecademy
  - Khan Academy
  - Udacity
  - edX
  - Alison
  - Lynda
  - NewCircle.com

Any advice?  Thanks!
--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

  




-- 
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/891ed395-21e8-80ac-8bf5-4598903cc748%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Try delete image file

2016-06-15 Thread Dariusz Mysior
I want change image and delete this changed when i save this new. I write 
delete method like below but it is not work, what is wrong?

models.py

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import MaxValueValidator, MinValueValidator
##

class MysiteUser(AbstractUser):
SINGLE = 'SI'
MARRIED = 'MA'
WIDOW = 'WI'
DIVORCEE = 'DI'
MARTIAL_STATUS = (
(SINGLE, 'kawaler'),
(MARRIED, 'zamężna/żonaty'),
(WIDOW, 'wdowiec/wdowa'),
(DIVORCEE, 'rozwodnik')
)
WOMAN = 'WO'
MAN = 'MA'
SEX = (
(WOMAN, 'kobieta'),
(MAN, 'mężczyzna')
)
DOLNOSLASKIE = 'DO'
KUJAWSKO_POMORSKIE = 'KP'
LUBELSKIE = 'LE'
LUBUSKIE = 'LU'
LODZKIE = 'LO'
MALOPOLSKIE = 'MA'
MAZOWIECKIE = 'MZ'
OPOLSKIE = 'OP'
PODKARPACKIE = 'PO'
PODLASKIE = 'PD'
POMORSKIE = 'PM'
SLASKIE = 'SL'
SWIETOKRZYSKIE = 'SW'
WARMINSKO_MAZURSKIE = 'WM'
WIELKOPOLSKIE = 'WI'
ZACHODNIOPOMORSKIE = 'ZA'
PROVINCE = (
(DOLNOSLASKIE, 'dolnośląskie'),
(KUJAWSKO_POMORSKIE, 'kujawsko-pomorskie'),
(LUBELSKIE, 'lubelskie'),
(LUBUSKIE, 'lubuskie'),
(LODZKIE, 'łódzkie'),
(MALOPOLSKIE, 'małopolskie'),
(MAZOWIECKIE, 'mazowieckie'),
(OPOLSKIE, 'opolskie'),
(PODKARPACKIE, 'podkarpackie'),
(PODLASKIE, 'podlaskie'),
(POMORSKIE, 'pomorskie'),
(SLASKIE, 'śląskie'),
(SWIETOKRZYSKIE, 'świętokrzyskie'),
(WARMINSKO_MAZURSKIE, 'warmińsko-mazurskie'),
(WIELKOPOLSKIE, 'wielkopolskie'),
(ZACHODNIOPOMORSKIE, 'zachodniopomorskie')
)
PODSTAWOWE = 'PO'
SREDNIE = 'SR'
WYZSZE = 'WY'
EDUCATION = (
(PODSTAWOWE,'podstawowe'),
(SREDNIE,'średnie'),
(WYZSZE,'wyższe'),
)
KATOLIK = 'KA'
PRAWOSLAWNY = 'PR'
PROTESTANT = 'PO'
BUDDYZM = 'BU'
ISLAM = 'IS'
ATEISTA = 'AT'
INNA_RELIGIA = 'IN'
RELIGION = (
(KATOLIK, 'katolik'),
(PRAWOSLAWNY, 'prawosławny'),
(PROTESTANT, 'protestant'),
(BUDDYZM, 'buddyzm'),
(ISLAM, 'islam'),
(ATEISTA, 'ateista'),
(INNA_RELIGIA, 'inna religia')
)
YES = 'YS'
NO = 'NO'
CHOICES = (
(YES, 'tak'),
(NO, 'nie')
)

sex = models.CharField(blank=False, max_length=20, choices=SEX, 
default=WOMAN)
avatar = models.ImageField(upload_to="avatar", null=True, blank=True)
age = models.PositiveSmallIntegerField(null=True, blank=True, 
validators=[MinValueValidator(1), MaxValueValidator(100)])
joined_time = models.DateTimeField(auto_now_add=True)
martial_status = models.CharField(max_length=20, choices=MARTIAL_STATUS, 
default=SINGLE)
province = models.CharField(max_length=20, choices=PROVINCE, 
default=DOLNOSLASKIE)
city = models.CharField(max_length=30)
education = models.CharField(max_length=20, choices=EDUCATION, 
default=PODSTAWOWE)
religion = models.CharField(max_length=20, choices=RELIGION, 
default=KATOLIK)
kids = models.NullBooleanField(blank=True, choices=CHOICES)
are_smoke = models.NullBooleanField(blank=True, choices=CHOICES)
are_drink = models.NullBooleanField(blank=True, choices=CHOICES)
def __str__(self):
return self.username

   def delete(self):
MysiteUser.objects.filter(avatar = self).delete()
self.avatar.delete()
return super(MysiteUser,self).delete()

def save(self):
self.delete()
return super(MysiteUser, self).save()



-- 
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/a24ee92c-13a7-4172-aafb-184eded32782%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Absolute beginner step by step

2016-06-15 Thread Shaylee Hansen
Thanks for the update on the new Tango With Django.   Everyone highly 
recommends this tutorial so I'm excited to see its recently been updated :) 

On Monday, June 13, 2016 at 12:51:07 PM UTC-6, gary719_list1 wrote:
>
> I stand corrected. There is a new Tango With Django tutorial out. It uses 
> Python 3.5 and Django 1.9. Try /
> media.readthedocs.org/pdf/tango-with-django/latest/tango-with-django.pdf
>
> Gary R
>
> On 06/11/2016 02:07 PM, Gary Roach wrote:
>
> If you don't mind working with Python2.7 and Django 1.7 you might try 
> "Tango With Django" . It is out of date but still is a good place to start. 
> Too bad that the author hasn't updated it. I have had some success with 
> running three projects in parallel. Tango along with the official Django 
> howto and another with your own project if you have one. I saw a reference 
> to "Learning Python The  Hard Way". It's a good choice.
>
> One nasty thing you may run into if you run parallel programs is the use 
> of multiple version of Python and Django. If you use virtualenv and pyvenv 
> to set up multiple virtual environments and then point your IDE at the one 
> needed for a particular project, you should be ok. You don't even have to 
> activate the environments because you are using them for storage of python 
> and django versions only.
>
> Good luck
>
> Gary R.
>
>
> On 06/10/2016 07:32 PM, Mc. Holid wrote:
>
> Dear All,
>
> Could anyone help  to share the point for absolute beginner guide. 
>
> I have already know a little bit about html, and having strong background 
> in vb6.
>
> Thanks for any kind help.
>
> Best Regards
> Mchoud
> -- 
> 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/d2fa7fd5-2673-4292-a14e-482e148587bb%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...@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/575C7D80.7060206%40verizon.net
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
-- 
 

NOTICE: This email and attached file(s) contain Gcommerce Solutions, LLC 
confidential information intended for the exclusive use of the 
individual(s) to whom addressed. If you are not the intended recipient, 
please immediately delete this Email (and attached files) and treat the 
information as confidential.

-- 
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/b4c64c46-02a6-4237-bbff-b4b3fbd0d6e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


https://docs.djangoproject.com/en/1.9/intro/reusable-apps/

2016-06-15 Thread Anas Ghrab
Hi,

I made a reusable-app following the this tutorial :

https://docs.djangoproject.com/en/1.9/intro/reusable-apps/

The app works, but not the translation of the different messages that are 
in the locale folder. When I change the LANGUAGE_CODE value in the 
settings.py file, the django admin follows the choosen language (groups, 
users), but not the name of the models are not translated.

Thanks you for your help,

---
Anas Ghrab

-- 
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/62fcc59f-ab25-4f67-b059-5f2abcf0fd39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to use view function in another function of view in django

2016-06-15 Thread hossein


def base(request):
j=Job.objects.all()
a=Ab.objects.all()
return render(request,'base.html',{'j':j, 'a':a})

def index(request):
base(request)
x=X.objects.all()
return render(request, 'index.html',{'x':x})

def list(request):
base(request)
z=Z.objects.all()
return render(request, 'list.html',{'z':z})

-- 
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/3cc2651c-35df-4eaf-bab6-b1ae936f73d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Absolute beginner step by step

2016-06-15 Thread Derek
If you are getting syntax errors, it is best to post the relevant code 
here, along with the Python stack trace. English is usually not good at 
describing programming errors.

On Tuesday, 14 June 2016 23:56:02 UTC+2, Mc. Holid wrote:
>
> Dear All
>
> It seem this is the best starting guide for me, 
>
> Just one to ask about the tips and trick how do you deal with the so many 
> "unknown syntax", some time we have to use this ' character some time use 
> ", then mention the name of a database field followed with array. Could 
> anyone suggest for me the suitable and comprehensive exercise for fluent in 
> Django syntax, May be i have to try and try again with 
> learningpyhtonthehardway ?
>
> As my background try to deciding django is  seeing the motto "The web 
> framework for perfectionists with deadlines.
> I got a little social project, is there a forum for mentoring or exchange 
> any experience and knowledge for project based discussion.
>
>
> Thanks for any kind help.
> Best Regards
> Kholid
>
> On Tuesday, June 14, 2016 at 1:51:07 AM UTC+7, gary719_list1 wrote:
>>
>> I stand corrected. There is a new Tango With Django tutorial out. It uses 
>> Python 3.5 and Django 1.9. Try /
>> media.readthedocs.org/pdf/tango-with-django/latest/tango-with-django.pdf
>>
>> Gary R
>>
>> On 06/11/2016 02:07 PM, Gary Roach wrote:
>>
>> If you don't mind working with Python2.7 and Django 1.7 you might try 
>> "Tango With Django" . It is out of date but still is a good place to start. 
>> Too bad that the author hasn't updated it. I have had some success with 
>> running three projects in parallel. Tango along with the official Django 
>> howto and another with your own project if you have one. I saw a reference 
>> to "Learning Python The  Hard Way". It's a good choice.
>>
>> One nasty thing you may run into if you run parallel programs is the use 
>> of multiple version of Python and Django. If you use virtualenv and pyvenv 
>> to set up multiple virtual environments and then point your IDE at the one 
>> needed for a particular project, you should be ok. You don't even have to 
>> activate the environments because you are using them for storage of python 
>> and django versions only.
>>
>> Good luck
>>
>> Gary R.
>>
>>
>> On 06/10/2016 07:32 PM, Mc. Holid wrote:
>>
>> Dear All,
>>
>> Could anyone help  to share the point for absolute beginner guide. 
>>
>> I have already know a little bit about html, and having strong background 
>> in vb6.
>>
>> Thanks for any kind help.
>>
>> Best Regards
>> Mchoud
>> -- 
>> 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/d2fa7fd5-2673-4292-a14e-482e148587bb%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...@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/575C7D80.7060206%40verizon.net
>> .
>> 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/541d1b69-b4fb-42b3-8f77-aaebe8c27ae9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: passing url variables to views

2016-06-15 Thread Lusine Hovsepyan
Hi dk.
If I understand well, you want to pass args from JS / HTML to  python view ?

Are you try url(r'^run_delete(.*)', views.run_delete, name='run_delete')   ?

Thanks

>
>

-- 
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/1d8cd068-b9b7-4527-a5d2-3da458c49ba4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: passing url variables to views

2016-06-15 Thread Lusine Hovsepyan
Hi dk.
If I understand well, you want to pass arg of JS / HTML to python view ?

Are you try url(r'^run_delete(.*)', views.run_delete, name='run_delete') ?

Thanks

вторник, 31 мая 2016 г., 13:33:59 UTC+4 пользователь dk написал:
>
> this is the URS i get
>
> http://127.0.0.1:8000/my_app/run_delete/?user_del=ccc_ccc***a_b***/
>
> and i want to be able to get the string  *ccc_ccc***a_b
>
> my url pattern is: 
>
> url(r'^run_delete/(?P\w+)/$', views.run_delete, name='run_delete')
>
>
>
> but it looks like is not catching it,   i am missing something? i am using 
> django 1.9
>
> thanks guys
>
>

-- 
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/03d0b99a-44c4-4344-ae04-d4c078d9b4b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Date() in Django query

2016-06-15 Thread Simon Charette
Hi Galil,

in this case you'll want to take a look at how `values()` and `annotate()` 
interact with
each others[1] in regard to GROUP BY.

The following should do:

Call.objects.annotate(
joindate=Func(F('jointime'), function='DATE')
).values('joindate').annotate(  # values before annotate() specifies the 
GROUP BY
count=Count('uniquecallid', distinct=True)
)

Cheers,
Simon

[1] https://docs.djangoproject.com/en/1.9/topics/db/aggregation/#values

Le mercredi 15 juin 2016 07:58:55 UTC-4, Galil a écrit :
>
> Thank you Simon,
>
> This func expression what was I looking for. However, some more complex 
> queries with the date() function still confuse me.
>
> For example the SQL query:
>
> select count(distinct UniqueCallID), date(JoinTime) from Table group by 
> date(JoinTime);
>
>
> I tried to write it as:
>
> calls = Call.objects.annotate(join_date=Func(F('jointime'), function='DATE'), 
> count=Count('uniquecallid', distinct=True)).values('join_date', 'count')
>
>
> But it seems that the group by is not working as expected and the values 
> returned are not distinct. Am I missing something?
>
>
> On Wednesday, 15 June 2016 04:08:48 UTC+1, Simon Charette wrote:
>>
>> Hi Galil,
>>
>> In the next version of Django (1.10) you'll be able to use the TruncDate 
>> expression[1]
>> for this exact purpose:
>>
>> MyModel.objects.annotate(join_date=TruncDate('join_time')).values_list('join_date',
>>  
>> flat=True)
>>
>> In the mean time you can simply use a Func expression[2]:
>>
>> MyModel.objects.annotate(join_date=Func(F('join_time'), 
>> function='DATE')).values_list('join_date', flat=True)
>>
>> Cheers,
>> Simon
>>
>> [1] 
>> https://docs.djangoproject.com/en/1.10/ref/models/database-functions/#django.db.models.functions.datetime.TruncDate
>> [2] 
>> https://docs.djangoproject.com/en/1.9/ref/models/expressions/#func-expressions
>>
>> Le mardi 14 juin 2016 09:52:34 UTC-4, Galil a écrit :
>>>
>>> Hi, 
>>>
>>> How can I convert this SQL query into a Django query?
>>>
>>> SELECT DATE(JoinTime) FROM table
>>>
>>> Please keep in mind that JoinTime is in datetime format and I want it to 
>>> be date.
>>>
>>> Thanks
>>>
>>>
>  
>

-- 
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/b39dbfd6-1bf5-4dec-8129-f362d7f30696%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Date() in Django query

2016-06-15 Thread Galil
Thank you Simon,

This func expression what was I looking for. However, some more complex 
queries with the date() function still confuse me.

For example the SQL query:

select count(distinct UniqueCallID), date(JoinTime) from Table group by 
date(JoinTime);


I tried to write it as:

calls = Call.objects.annotate(join_date=Func(F('jointime'), function='DATE'), 
count=Count('uniquecallid', distinct=True)).values('join_date', 'count')


But it seems that the group by is not working as expected and the values 
returned are not distinct. Am I missing something?


On Wednesday, 15 June 2016 04:08:48 UTC+1, Simon Charette wrote:
>
> Hi Galil,
>
> In the next version of Django (1.10) you'll be able to use the TruncDate 
> expression[1]
> for this exact purpose:
>
> MyModel.objects.annotate(join_date=TruncDate('join_time')).values_list('join_date',
>  
> flat=True)
>
> In the mean time you can simply use a Func expression[2]:
>
> MyModel.objects.annotate(join_date=Func(F('join_time'), 
> function='DATE')).values_list('join_date', flat=True)
>
> Cheers,
> Simon
>
> [1] 
> https://docs.djangoproject.com/en/1.10/ref/models/database-functions/#django.db.models.functions.datetime.TruncDate
> [2] 
> https://docs.djangoproject.com/en/1.9/ref/models/expressions/#func-expressions
>
> Le mardi 14 juin 2016 09:52:34 UTC-4, Galil a écrit :
>>
>> Hi, 
>>
>> How can I convert this SQL query into a Django query?
>>
>> SELECT DATE(JoinTime) FROM table
>>
>> Please keep in mind that JoinTime is in datetime format and I want it to 
>> be date.
>>
>> Thanks
>>
>>
 

-- 
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/d663318b-59b6-47e5-9cbd-f08cc4db0906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to execute annotation from one model on second, for get new fied?

2016-06-15 Thread Seti Volkylany

I have two models: Book and Reply


*the model Book*


class Book(models.Model):
"""
Model for books
"""

# other fields

replies = GenericRelation(Reply, related_query_name='books')

# managers
objects = models.Manager()
objects = BookManager.from_queryset(BookQuerySet)()

# other methods

def get_rating(self):
"""Getting rating of book on based scopes."""

# return 
self.__class__.objects.books_with_rating().get(pk=self.pk).rating
replies_with_total_scope = self.replies.replies_with_total_scope()
rating = replies_with_total_scope.aggregate(rating=models.Avg(
'total_scope'))['rating']
rating = rating or 0
return round(rating, 4)
get_rating.admin_order_field = 'rating'
get_rating.short_description = _('Rating')


*model Reply*

from django.utils import timezone
# from django.core.exceptions import ValidationError
from django.contrib.postgres.fields import ArrayField
from django.core.validators import MinLengthValidator, MaxValueValidator
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.conf import settings

from mylabour.models import BaseGenericModel
from mylabour.validators import MaxCountWordsValidator, 
MinCountWordsValidator, OnlyLettersValidator

from .querysets import ReplyQuerySet

class Reply(BaseGenericModel):
"""
Model for reply about other objects.
"""

MAX_SCOPE = 5
MIN_SCOPE = 1

account = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='replies',
verbose_name=_('user'),
)
impress = models.CharField(
_('impress (brief)'),
max_length=50,
validators=[MinLengthValidator(10)],
help_text=_('From 10 to 50 characters.'),
)
advantages = ArrayField(
models.CharField(max_length=20, validators=[OnlyLettersValidator]),
size=10,
verbose_name=_('advantages'),
help_text=_('Listing from 1 to 10 words separated commas.'),
error_messages={
'blank': 'Enter at least one word.',
# 'item_invalid': 'Word is not correct.',
}
)
disadvantages = ArrayField(
models.CharField(max_length=20, validators=[OnlyLettersValidator]),
help_text=_('Listing from 1 to 10 words separated commas.'),
verbose_name=_('disadvantages'),
size=10,
error_messages={
'blank': 'Enter at least one word.',
'item_invalid': 'Word is not correct.',
}
)
text_reply = models.TextField(
_('text of reply'),
validators=[MinCountWordsValidator(10), MaxCountWordsValidator(100
)],
help_text=_('From 10 to 100 words.'),
)
scope_for_content = models.PositiveSmallIntegerField(
_('scope for content'),
default=MIN_SCOPE,
validators=[
MaxValueValidator(MAX_SCOPE, _('The scope for content must be 
from 1 to %d' % MAX_SCOPE))
])
scope_for_style = models.PositiveSmallIntegerField(
_('scope for style'),
default=MIN_SCOPE,
validators=[
MaxValueValidator(MAX_SCOPE, _('The scope for style must be 
from 1 to %d' % MAX_SCOPE))
])
scope_for_language = models.PositiveSmallIntegerField(
_('scope for language'),
default=MIN_SCOPE,
validators=[
MaxValueValidator(MAX_SCOPE, _('The scope for language must be 
from 1 to %d' % MAX_SCOPE))
])
date_added = models.DateTimeField(_('Date aded'), auto_now_add=True)

# managers
objects = models.Manager()
objects = ReplyQuerySet.as_manager()

# other methods

def get_total_scope(self):
return self.__class__.objects.replies_with_total_scope().get(pk=self
.pk).total_scope
get_total_scope.admin_order_field = 'total_scope'
get_total_scope.short_description = _('Total scope')


*Custom queryset for model Reply*


from django.db import models

from mylabour.functions_db import Round

class ReplyQuerySet(models.QuerySet):
"""
QuerySet for replies.
"""

def replies_with_total_scope(self):
"""Determining average scope for each reply by their scopes: for 
content, for style, for language."""

# getting total sum all of the scopes
self = self.annotate(
sum_scope=models.F('scope_for_content') + models.F(
'scope_for_style') + models.F('scope_for_language')
)
# determining avg scope
self = self.annotate(total_scope=models.ExpressionWrapper(
models.F('sum_scope') / models.Value(3.0), output_field=models.
FloatField()
))
# make round for avg scope
self = self.annotate(total_scope=Round('total_scope'))
return self

Question next.
I need create queryset method to determinate rating of the each book. For 
it, I need have field 'total_scope' for each reply in a model Book.

I am attemped made