Re: CSS question for the Admin

2016-06-02 Thread Luis Zárate
Include your own CSS en admin meta


class myAdmin(admin.ModelAdmin):

 class Meta:
   css ={'all': ['yourcss.css']}



El jueves, 2 de junio de 2016, Mike Dewhirst 
escribió:
> On 2/06/2016 7:31 PM, Michal Petrucha wrote:
>>
>> On Thu, Jun 02, 2016 at 07:22:16PM +1000, Mike Dewhirst wrote:
>>>
>>> I have a varchar field of 300+ chars and I'd like to know how to provide
>>> space to wrap it on screen without resorting to a TextField
>>>
>>> Any CSS ideas?
>>>
>>> Thanks
>>>
>>> Mike
>>
>> Perhaps you could override the widget to a Textarea with the right
>> maxlength attribute? That should be fine if you don't target IE<10...
>
> I'm guessing I have to first inherit the admin form for the page involved
then tweak the widget.
>
> Haven't played there before. Back to the docs ...
>
> Thank you Michal
>
> Cheers
>
> Mike
>
>>
>> Cheers,
>>
>> Michal
>>
>
> --
> 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/c15c5d17-075a-542c-31c3-35cc1f1d3120%40dewhirst.com.au
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyPuSvK0n2OcLOm%2BhguE44iSc32rNMq%2BCvRie%3DUQkowCYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Installation Advice - Win/PostgreSQL/Django

2016-06-02 Thread Avraham Serour
For development you only really need django, you can develop with sqlite
and deploy on a server using postgres, using postgres on the development
machine is nice but not strictly necessary.
If this is for a production machine you will also need a webserver
On Jun 2, 2016 10:56 PM, "Rafael E. Ferrero" 
wrote:

Where did you unzipped Django? (use pip command to install Django, and
please use venv, virtualenvwrapper o virtualenvironment)

Take a look of this https://docs.djangoproject.com/en/1.8/howto/windows/



Rafael E. Ferrero

2016-06-02 15:30 GMT-03:00 :

> Hi, folks,
>
> I have found a lot of Django installation checklists out there. Most are
> for very old versions. Others are rather vague, since they cover so many
> options. Still others assume that everything is hosted somewhere else. I
> have not yet been able to get the whole stack working in a local
> environment.
>
> Here's what I have done so far for my Windows development machine. If any
> of you could advise on how to get to the next steps, I would really
> appreciate it.
>
>
>- Working, stable installation of Windows 7 (x64)
>- Installed PostgreSQL 9.5.2
>- Created a schema
>   - Created some tables
>   - Imported some data
>   - So far so good
>- Installed Python 3.5.0
>- (Started with 3.6 but had to downgrade repeatedly to find a version
>   compatible with psycopg2)
>   - Win 64
>   - C:\> python -- version returns 3.5.0
>   - Again, so far so good
>- Installed psycopg2
>   - Version 2.6.1
>   - Win 64 (psycopg2-2.6.1.win-amd64-py3.5.exe)
>   - Seems to be installed correctly
>   - This is the latest version. (It seems to be a beta-test release.
>   It's a little hard to tell. However, it supports Python 3.5.)
>- Django 1.9.6
>- Downloaded and unzipped
>   - Didn't get any errors
>   - >>> import django
>   - No joy.
>- PIP
>- Whatever comes built into Python
>   - Not entirely sure what version
>   - Command line responds
>   - Not sure what to do with it
>
> Are there more layers to install? Do you see any obvious version issues?
> One thing I noticed is that my Windows PATH environment variable is very
> long. If any of these modules are appending to it, that may not be working.
> I could try weeding stuff out of my PATH, but that seems like a long shot.
>
> Thanks a million!
>
> --
> 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/296c0f10-2e6b-45cd-8407-2b78ec5ba716%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/CAJJc_8XWG6pRR28FR1%2B%2BK1K7RjPpJ7WhyzRTycgZ50W2s31aoQ%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/CAFWa6tKcsjuFB0-8vaHou1NfOXiCZMhgR3aW244ZhZ5Zy%2Buu4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Installation Advice - Win/PostgreSQL/Django

2016-06-02 Thread Rafael E. Ferrero
Where did you unzipped Django? (use pip command to install Django, and
please use venv, virtualenvwrapper o virtualenvironment)

Take a look of this https://docs.djangoproject.com/en/1.8/howto/windows/



Rafael E. Ferrero

2016-06-02 15:30 GMT-03:00 :

> Hi, folks,
>
> I have found a lot of Django installation checklists out there. Most are
> for very old versions. Others are rather vague, since they cover so many
> options. Still others assume that everything is hosted somewhere else. I
> have not yet been able to get the whole stack working in a local
> environment.
>
> Here's what I have done so far for my Windows development machine. If any
> of you could advise on how to get to the next steps, I would really
> appreciate it.
>
>
>- Working, stable installation of Windows 7 (x64)
>- Installed PostgreSQL 9.5.2
>- Created a schema
>   - Created some tables
>   - Imported some data
>   - So far so good
>- Installed Python 3.5.0
>- (Started with 3.6 but had to downgrade repeatedly to find a version
>   compatible with psycopg2)
>   - Win 64
>   - C:\> python -- version returns 3.5.0
>   - Again, so far so good
>- Installed psycopg2
>   - Version 2.6.1
>   - Win 64 (psycopg2-2.6.1.win-amd64-py3.5.exe)
>   - Seems to be installed correctly
>   - This is the latest version. (It seems to be a beta-test release.
>   It's a little hard to tell. However, it supports Python 3.5.)
>- Django 1.9.6
>- Downloaded and unzipped
>   - Didn't get any errors
>   - >>> import django
>   - No joy.
>- PIP
>- Whatever comes built into Python
>   - Not entirely sure what version
>   - Command line responds
>   - Not sure what to do with it
>
> Are there more layers to install? Do you see any obvious version issues?
> One thing I noticed is that my Windows PATH environment variable is very
> long. If any of these modules are appending to it, that may not be working.
> I could try weeding stuff out of my PATH, but that seems like a long shot.
>
> Thanks a million!
>
> --
> 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/296c0f10-2e6b-45cd-8407-2b78ec5ba716%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/CAJJc_8XWG6pRR28FR1%2B%2BK1K7RjPpJ7WhyzRTycgZ50W2s31aoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test fails when run in whole test suite - but not stand-alone?

2016-06-02 Thread Adam Stein
When I've had that happen before, it's because some previous test
changed something (like a setting value or the site domain) that
influenced the test that failed. To narrow it down, I would run all the
tests up to and including the failed one. That should fail, then I
start taking out half the tests before. If the test still fails, I keep
cutting in half until I can determine which previous test is causing
issues. If, after cutting out tests, the problem test passes, then I
need to put back in what I took out since it was one of those.
Once I figure out which previous test it was, I can start removing the
individual tests to finally get to the code causing the problem.
Usually, it's a case that a test changed something and I just have to
add in the teardown function to restore the state of whatever was
changed.
On Thu, 2016-06-02 at 21:33 +0200, Derek wrote:
> I have a test that is failing when the file it is in is run as part
> of all the other test files by the test runner.
> 
> If I just run only the file that contains this test -  then it
> passes.
> 
> (pass/fail refers to the very last assert in the code below.)
> 
> I'd appreciate any ideas or insights from anyone who can spot an
> obvious mistake - or suggest some options to explore.
> 
> Thanks
> Derek
> 
> 
> # THIS IS AN EXTRACT OF RELEVANT CODE (not all of it...)
> from django.contrib.messages.storage.fallback import FallbackStorage
> from django.core.urlresolvers import reverse
> from django.test import TestCase, Client
> # ... various app-related imports ...
> 
> 
> class MockRequest(object):
>     """No code needed."""
>     pass
> 
> 
> REQUEST = MockRequest()
> # see: https://stackoverflow.com/queI stions/11938164/why-dont-my-
> django-\
> #      unittests-know-that-messagemiddleware-is-installed
> setattr(REQUEST, 'session', 'session')
> MESSAGES = FallbackStorage(REQUEST)
> setattr(REQUEST, '_messages', MESSAGES)
> setup_test_environment()
> 
> 
> class PersonAdminTest(TestCase):
> 
>     def setUp(self):
>         self.user, password = utils.user_factory(model=None)
>         self.client = Client()
>         login_status = self.client.login(username=self.user.email,
> password=password)
>         self.assertEqual(login_status, True)
> 
>     def test_action_persons_make_unreal(self):
>         try:
>             change_url =
> reverse('admin:persons_realpersons_changelist')
>         except NoReverseMatch:
>             change_url = '/admin/persons/realpersons/'
>             sys.stderr.write('\n   WARNING: Unable to reverse URL!
> ... ')
>         response = self.client.get(change_url)
>         self.assertEqual(response.status_code, 200)
> 
> -- 
> 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/CAF1Wu3MoGgm_dSToObDX9gH7GQJ%3DTZzGLV7RPOiZk4kvV-
> _Nbg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
-- 
Adam (a...@csh.rit.edu)


-- 
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/1464896791.20313.13.camel%40csh.rit.edu.
For more options, visit https://groups.google.com/d/optout.


Installation Advice - Win/PostgreSQL/Django

2016-06-02 Thread cbt
Hi, folks,

I have found a lot of Django installation checklists out there. Most are 
for very old versions. Others are rather vague, since they cover so many 
options. Still others assume that everything is hosted somewhere else. I 
have not yet been able to get the whole stack working in a local 
environment. 

Here's what I have done so far for my Windows development machine. If any 
of you could advise on how to get to the next steps, I would really 
appreciate it.


   - Working, stable installation of Windows 7 (x64)
   - Installed PostgreSQL 9.5.2
   - Created a schema
  - Created some tables
  - Imported some data
  - So far so good
   - Installed Python 3.5.0
   - (Started with 3.6 but had to downgrade repeatedly to find a version 
  compatible with psycopg2)
  - Win 64
  - C:\> python -- version returns 3.5.0
  - Again, so far so good
   - Installed psycopg2
  - Version 2.6.1
  - Win 64 (psycopg2-2.6.1.win-amd64-py3.5.exe)
  - Seems to be installed correctly
  - This is the latest version. (It seems to be a beta-test release. 
  It's a little hard to tell. However, it supports Python 3.5.)
   - Django 1.9.6
   - Downloaded and unzipped
  - Didn't get any errors
  - >>> import django
  - No joy.
   - PIP 
   - Whatever comes built into Python
  - Not entirely sure what version
  - Command line responds
  - Not sure what to do with it
   
Are there more layers to install? Do you see any obvious version issues?
One thing I noticed is that my Windows PATH environment variable is very 
long. If any of these modules are appending to it, that may not be working. 
I could try weeding stuff out of my PATH, but that seems like a long shot.

Thanks a million!

-- 
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/296c0f10-2e6b-45cd-8407-2b78ec5ba716%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Test fails when run in whole test suite - but not stand-alone?

2016-06-02 Thread Derek
I have a test that is failing when the file it is in is run as part of all
the other test files by the test runner.

If I just run only the file that contains this test -  then it passes.

(pass/fail refers to the very last assert in the code below.)

I'd appreciate any ideas or insights from anyone who can spot an obvious
mistake - or suggest some options to explore.

Thanks
Derek


# THIS IS AN EXTRACT OF RELEVANT CODE (not all of it...)
from django.contrib.messages.storage.fallback import FallbackStorage
from django.core.urlresolvers import reverse
from django.test import TestCase, Client
# ... various app-related imports ...


class MockRequest(object):
"""No code needed."""
pass


REQUEST = MockRequest()
# see: https://stackoverflow.com/queI stions/11938164/why-dont-my-django-\
#  unittests-know-that-messagemiddleware-is-installed
setattr(REQUEST, 'session', 'session')
MESSAGES = FallbackStorage(REQUEST)
setattr(REQUEST, '_messages', MESSAGES)
setup_test_environment()


class PersonAdminTest(TestCase):

def setUp(self):
self.user, password = utils.user_factory(model=None)
self.client = Client()
login_status = self.client.login(username=self.user.email,
password=password)
self.assertEqual(login_status, True)

def test_action_persons_make_unreal(self):
try:
change_url = reverse('admin:persons_realpersons_changelist')
except NoReverseMatch:
change_url = '/admin/persons/realpersons/'
sys.stderr.write('\n   WARNING: Unable to reverse URL! ... ')
response = self.client.get(change_url)
self.assertEqual(response.status_code, 200)

-- 
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/CAF1Wu3MoGgm_dSToObDX9gH7GQJ%3DTZzGLV7RPOiZk4kvV-_Nbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Suit admin panel - Static files configuration Django 1.6 not working

2016-06-02 Thread Roger Lanoue jr
I am rebuilding a new server from scratch now. 

New IP: Same setup with new IP from Digital Ocean 1click install - 

http://162.243.58.204/

I am going to try and setup the Static files directory again. 

Since they are using Django 1.6 and the command makemigration and migrate 
are not in 1.6
Should i start using Django 1.8 or 1.9 before configuring the server?

On Thursday, June 2, 2016 at 10:35:20 AM UTC-4, luisza14 wrote:
>
> Where is  STATIC_ROOT ?
>
> static_root path needs to match with nginx /static location.
>
>
>
> El miércoles, 1 de junio de 2016, Roger Lanoue jr  > escribió:
> > Hi Django users group.
> > I am test and learning django out. I have a testing server and got my 
> test page up. 
> > Started to play with the Django suit control panel and ran in to some 
> problems with my setup.
> > Server: Digital Ocean one click install.
> > Ubuntu 14.04
> > Nginx
> > Postgres
> > python 2.7
> > django 1.6
> > Test server
> > http://162.243.201.237/
> >
> > Admin panel: http://django-suit.readthedocs.io/en/develop/
> > http://162.243.201.237/admin/
> > user: demo
> > pasword: demo
> > Static file command I ran
> > python manage.py collectstatic
> >
> > results: 0 static files copied, 116 unmodified.
> > Setting.py: Basics 
> > DEBUG = False 
> > TEMPLATE_DEBUG = False
> > ALLOWED_HOSTS = ['*']
> >
> > STATIC_URL = '/static/'
> > STATICFILES_DIRS = [
> > os.path.join(BASE_DIR, "static"),
> > '/home/django/django_project/static/',
> > Nginx setting:
> >  # Your Django project's media files - amend as required
> > location /media  {
> > alias /home/django/django_project/django_project/media;
> > }
> > # your Django project's static files - amend as required
> > location /static {
> > alias /home/django/django_project/django_project/static; 
> > }
> > # Proxy the static assests for the Django Admin panel
> > location /static/admin {
> >alias 
> /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
> > }
> > location / {
> > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> > proxy_set_header Host $http_host;
> > proxy_redirect off;
> > proxy_pass http://app_server;
> > }
> >  My goal is to get the Django suit working. I do not see anything in my 
> static files directory for the admin suit so the css can be applied. 
> > I am missing something very simple to get this working.
> > Thank you for taking time to look at this and wish to get some clues.
> > Roger
> >
> > --
> > 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/f0c19816-b477-43ba-9953-d4793bdfac80%40googlegroups.com
> .
> > For more options, visit https://groups.google.com/d/optout.
> >
>
> -- 
> "La utopía sirve para caminar" Fernando Birri
>
>
>
>

-- 
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/b3a7b96a-d6c9-4595-b989-a987ada38fe9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: authenticate a user without databse

2016-06-02 Thread Stephen J. Butler
Did you use the login_required decorator on your view? Authentication is
something you have to specify you want for a page, it is not assumed.

https://docs.djangoproject.com/en/1.9/topics/auth/default/#the-login-required-decorator

On Thu, Jun 2, 2016 at 3:54 AM, prabhat jha 
wrote:

>  i have created a login page in django,where user will authenticate
> through c++ server i.e running in background.
> i made communication between c++ server and python server through name
> pipe(ipc).everything is working fine.
> but if user will type link of homepage without authentication of login
> page,this page is open.
>
> --
> 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/6234c1fe-f1f6-4056-b9b5-3219c85ccebe%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/CAD4ANxU2rV48aQqFsqpL162J4s3bVh1P3wdBp%2B9EfAT4ww6LJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Views.py & template (queryset)

2016-06-02 Thread Stephen J. Butler
Add date2016 to your context:

{ 'test': test, 'date2016': date2016 }

Then it's just {{ date2016 }} in your template.

On Thu, Jun 2, 2016 at 6:36 AM, Franck  wrote:

> Hello Stephen,
> Thanks for your help, ok I think it's better to used views for what I need
> to do.
> Last question, how I can define this in view and template ?
> For the moment I used 'for' & 'endfor' in my template to show all my
> items, but I want to show "date2016" in only one field.
>
> *Views.py*
> from .models import Test
> from datetime import datetime
> from django.shortcuts import render, get_object_or_404
>
> def test(request):
> test = Test.objects.order_by('name')
> *date2016 =
> Test.objects.filter(dateregister__contains='2016').count()*??
> return render(request, 'test/test.html', {'test': test})
>
>
> *Template:*
>
>
>
>
>
>
>
>
> *{% for test in test %}{{ test.name }}{{ test.dateregister
> }}{% endfor %}{% test.date2016 %}   Thanks for your help !*
>
> Le mercredi 1 juin 2016 19:00:41 UTC+2, Stephen Butler a écrit :
>>
>> From the template language reference:
>>
>> <
>> https://docs.djangoproject.com/en/1.9/ref/templates/language/#accessing-method-calls
>> >
>>
>> """
>> Because Django intentionally limits the amount of logic processing
>> available in the template language, it is not possible to pass arguments to
>> method calls accessed from within templates. Data should be calculated in
>> views, then passed to templates for display.
>> """
>>
>> If you want to do something like this then you're better switching to a
>> more complete template language, like Jinja2. But I'd also suggest you
>> prepare your querysets entirely before passing them to templates.
>>
>> Also, for Date/DateTime/Time fields you should use the lookups provided.
>> Do this instead: .filter(dateregister__year=2016)
>>
>> On Wed, Jun 1, 2016 at 11:30 AM, Franck  wrote:
>>
>>> Hello,
>>>
>>> First Django project... sorry ;-)
>>>
>>> I can run that in manage.py shell, result is ok.
>>> * Test.objects.filter(dateregister__contains='2016').count()*
>>>
>>> But how I can show this result in the template ?
>>> {{ test.count }} works directly in the template without modify views.py,
>>> I tried with
>>> *{{ test.filter(dateregister__contains='2016').count()** }}   but no
>>> result...*
>>>
>>>
>>> *Models.py*
>>>
>>> from __future__ import unicode_literals
>>> from django.db import models
>>> from django.utils import timezone
>>>
>>> class Test(models.Model):
>>> name = models.CharField(max_length=10, editable=False)
>>> dateregister = models.DateTimeField(auto_now=False, auto_now_add=
>>> False, null=True, blank=True, editable=False)
>>> def __str__(self):  # __unicode__ on Python 2
>>> return self.name
>>>
>>>
>>> *Views.py*
>>> from .models import Test
>>> from datetime import datetime
>>> from django.shortcuts import render, get_object_or_404
>>>
>>> def test(request):
>>> test = Test.objects.order_by('name')
>>> return render(request, 'test/test.html', {'test': test})
>>>
>>> Thanks for your 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...@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/03de09e4-1a70-4bf3-a669-dce6a22f24d9%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/f7f13063-3c98-4373-b238-b7ab9fb5e0d0%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 

Re: Django Suit admin panel - Static files configuration Django 1.6 not working

2016-06-02 Thread Luis Zárate
Where is  STATIC_ROOT ?

static_root path needs to match with nginx /static location.



El miércoles, 1 de junio de 2016, Roger Lanoue jr 
escribió:
> Hi Django users group.
> I am test and learning django out. I have a testing server and got my
test page up.
> Started to play with the Django suit control panel and ran in to some
problems with my setup.
> Server: Digital Ocean one click install.
> Ubuntu 14.04
> Nginx
> Postgres
> python 2.7
> django 1.6
> Test server
> http://162.243.201.237/
>
> Admin panel: http://django-suit.readthedocs.io/en/develop/
> http://162.243.201.237/admin/
> user: demo
> pasword: demo
> Static file command I ran
> python manage.py collectstatic
>
> results: 0 static files copied, 116 unmodified.
> Setting.py: Basics
> DEBUG = False
> TEMPLATE_DEBUG = False
> ALLOWED_HOSTS = ['*']
>
> STATIC_URL = '/static/'
> STATICFILES_DIRS = [
> os.path.join(BASE_DIR, "static"),
> '/home/django/django_project/static/',
> Nginx setting:
>  # Your Django project's media files - amend as required
> location /media  {
> alias /home/django/django_project/django_project/media;
> }
> # your Django project's static files - amend as required
> location /static {
> alias /home/django/django_project/django_project/static;
> }
> # Proxy the static assests for the Django Admin panel
> location /static/admin {
>alias
/usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
> }
> location / {
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header Host $http_host;
> proxy_redirect off;
> proxy_pass http://app_server;
> }
>  My goal is to get the Django suit working. I do not see anything in my
static files directory for the admin suit so the css can be applied.
> I am missing something very simple to get this working.
> Thank you for taking time to look at this and wish to get some clues.
> Roger
>
> --
> 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/f0c19816-b477-43ba-9953-d4793bdfac80%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyNMVuY1ju8w8%2BQpK33eHjPBjyKKBzK7b7yZP74Mo8wHHA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Hi - I'm new to Python and DJango

2016-06-02 Thread Luis Zárate
Sure,

It's good enough and more.

There is some development in ERP but nothing stable or usable (not that I
known).

So if you are interested in develop something could be great know about.

Note: I thing first step is search what programs exists and try to
collaborate with one, but if nothing is good enough then start with new
develop and look for help.



El miércoles, 1 de junio de 2016, Notty Smurfy 
escribió:
> Hi all,
> i'm new to Django. Can anyone advise if this framework is good enough to
develop for an ERP system?
> 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/14504a53-e11b-4d01-915f-5e545ae93f91%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyMJoCkY12F-7hcMUMyhBHd7yHwaCwJCbXBQJzYYRt8xhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Views.py & template (queryset)

2016-06-02 Thread Franck
Hello Stephen,
Thanks for your help, ok I think it's better to used views for what I need 
to do.
Last question, how I can define this in view and template ?
For the moment I used 'for' & 'endfor' in my template to show all my items, 
but I want to show "date2016" in only one field.

*Views.py*
from .models import Test
from datetime import datetime
from django.shortcuts import render, get_object_or_404

def test(request):
test = Test.objects.order_by('name')
*date2016 = Test.objects.filter(dateregister__contains='2016').count()* 
   ??
return render(request, 'test/test.html', {'test': test})


*Template:*








*{% for test in test %}{{ test.name }}{{ test.dateregister 
}}{% endfor %}{% test.date2016 %}   Thanks for your help !*

Le mercredi 1 juin 2016 19:00:41 UTC+2, Stephen Butler a écrit :
>
> From the template language reference:
>
> <
> https://docs.djangoproject.com/en/1.9/ref/templates/language/#accessing-method-calls
> >
>
> """
> Because Django intentionally limits the amount of logic processing 
> available in the template language, it is not possible to pass arguments to 
> method calls accessed from within templates. Data should be calculated in 
> views, then passed to templates for display.
> """
>
> If you want to do something like this then you're better switching to a 
> more complete template language, like Jinja2. But I'd also suggest you 
> prepare your querysets entirely before passing them to templates.
>
> Also, for Date/DateTime/Time fields you should use the lookups provided. 
> Do this instead: .filter(dateregister__year=2016)
>
> On Wed, Jun 1, 2016 at 11:30 AM, Franck  
> wrote:
>
>> Hello,
>>
>> First Django project... sorry ;-)
>>
>> I can run that in manage.py shell, result is ok.
>> * Test.objects.filter(dateregister__contains='2016').count()*
>>
>> But how I can show this result in the template ?
>> {{ test.count }} works directly in the template without modify views.py, 
>> I tried with 
>> *{{ test.filter(dateregister__contains='2016').count()** }}   but no 
>> result...*
>>
>>
>> *Models.py*
>>
>> from __future__ import unicode_literals
>> from django.db import models
>> from django.utils import timezone
>>
>> class Test(models.Model):
>> name = models.CharField(max_length=10, editable=False)
>> dateregister = models.DateTimeField(auto_now=False, auto_now_add=
>> False, null=True, blank=True, editable=False)
>> def __str__(self):  # __unicode__ on Python 2
>> return self.name
>>
>>
>> *Views.py*
>> from .models import Test
>> from datetime import datetime
>> from django.shortcuts import render, get_object_or_404
>>
>> def test(request):
>> test = Test.objects.order_by('name')
>> return render(request, 'test/test.html', {'test': test})
>>
>> Thanks for your 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...@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/03de09e4-1a70-4bf3-a669-dce6a22f24d9%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/f7f13063-3c98-4373-b238-b7ab9fb5e0d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django suit and Static files not working in Django 1.6

2016-06-02 Thread Roger Lanoue jr
Hello All.

I learning my first Django experience and I am making some headway. I am 
stuck on my test server and Django suit admin. 

I my goal is to get the new admin from Django suit to work.

*Server setup*
Ubuntu 14.04 ( A Digital Ocean VPS with one click install ) 
Django Version 1.6
Python: 2.7
Nginx
Postgres

*Test server *
http://162.243.201.237/

*Admin (with django suit installed ) *
http://django-suit.readthedocs.io/en/develop/
http://162.243.201.237/admin/

User: Demo
password: Demo

The css is being applied to the djando suit .

*Ran command:*
python manage.py collectstatic

Results: 0 static files copied, 116 unmodified.


*My setting.py basics*

DEBUG = False 

TEMPLATE_DEBUG = False

STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/home/django/django_project/static/',

When I look in to the static directory. nothing had been copied. 

Thank your for taking time to look at this and also sharing with me any 
clues on how to fix this.

Roger




-- 
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/ee2b40b1-0716-4f5b-b4f1-8f35a60d54f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


authenticate a user without databse

2016-06-02 Thread prabhat jha
 i have created a login page in django,where user will authenticate through 
c++ server i.e running in background.
i made communication between c++ server and python server through name 
pipe(ipc).everything is working fine.
but if user will type link of homepage without authentication of login 
page,this page is open.

-- 
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/6234c1fe-f1f6-4056-b9b5-3219c85ccebe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Hi - I'm new to Python and DJango

2016-06-02 Thread Notty Smurfy
Hi all,

i'm new to Django. Can anyone advise if this framework is good enough to 
develop for an ERP system?

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/14504a53-e11b-4d01-915f-5e545ae93f91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Suit admin panel - Static files configuration Django 1.6 not working

2016-06-02 Thread Roger Lanoue jr
Hi Django users group.

I am test and learning django out. I have a testing server and got my test 
page up. 

Started to play with the Django suit control panel and ran in to some 
problems with my setup.

*Server: Digital Ocean one click install.*
Ubuntu 14.04
Nginx
Postgres
python 2.7
django 1.6

*Test server*
http://162.243.201.237/

*Admin panel: *http://django-suit.readthedocs.io/en/develop/
http://162.243.201.237/admin/
user: demo
pasword: demo

*Static file command I ran*
python manage.py collectstatic

results: 0 static files copied, 116 unmodified.

*Setting.py: Basics *
DEBUG = False 

TEMPLATE_DEBUG = False

ALLOWED_HOSTS = ['*']

STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/home/django/django_project/static/',

*Nginx setting:*

 # Your Django project's media files - amend as required
location /media  {
alias /home/django/django_project/django_project/media;
}

# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/django_project/static; 
}

# Proxy the static assests for the Django Admin panel
location /static/admin {
   alias 
/usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}

 My goal is to get the Django suit working. I do not see anything in my 
static files directory for the admin suit so the css can be applied. 
I am missing something very simple to get this working.

Thank you for taking time to look at this and wish to get some clues.

Roger

-- 
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/f0c19816-b477-43ba-9953-d4793bdfac80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CSS question for the Admin

2016-06-02 Thread Mike Dewhirst

On 2/06/2016 7:31 PM, Michal Petrucha wrote:

On Thu, Jun 02, 2016 at 07:22:16PM +1000, Mike Dewhirst wrote:

I have a varchar field of 300+ chars and I'd like to know how to provide
space to wrap it on screen without resorting to a TextField

Any CSS ideas?

Thanks

Mike


Perhaps you could override the widget to a Textarea with the right
maxlength attribute? That should be fine if you don't target IE<10...


I'm guessing I have to first inherit the admin form for the page 
involved then tweak the widget.


Haven't played there before. Back to the docs ...

Thank you Michal

Cheers

Mike



Cheers,

Michal



--
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/c15c5d17-075a-542c-31c3-35cc1f1d3120%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9 - Create an app that use the models from another app and dynamic CBV

2016-06-02 Thread sevenrrainbow
Thanks you James, 

To make it more clear.  Let's say I have companies(entities) and 
products(sub-entities) to be more clear. Regarding  the urls I use the main 
urls.py to include the urls.py from each app.

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^companies/', include('company.urls', namespace='company'))

 In the entity app the urls.py :

urlpatterns = [
url(r'^$', CompanyListView.as_view(), name='list'),
url(r'^add/$', EntityCreateView.as_view(), name='create'),



*Normal View*

/companies/  - listing all
/companies/company-name/ - details about a company
/companies/products/ - listing all products of a company
/products/ - listing all products
/products/product/  - details about a product

*Editor*

/account/   - dashboard)
/account/add   - adding a company, the company is actually the account, no 
other info for account, and is onetoone relationship with user
/account/edit -update company data
/account/company-name/products/add - add a product to company
/account/company-name/product-name/edit - update product info 

The account app I try to use is to control the account, even if doesn't 
exist a model. I understand that I can use multiple urls patterns in 
urls.py for an app in general, *but can you gave me an example for the case 
above ? *(having just two apps companies and products)

 At the view level 

In the Dashboard(account) first I verify if the company exist and 
activated(approved by admin(boolean field). 

If the company doesn't exist(first time) show the CreateView(CBV) form, if 
exists and activated show the company info and others and if it is not 
activated show a Pending message.

Based on the solutions you presented, I think is having a generic view 
(empty with only logic or with one of the cases(pending,exist and active)) 
and to redirect to different urls and corresponding views.  

Or you think there is a better approach ?













-- 
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/7cbff87a-4823-47ae-b06e-c061234d67e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CSS question for the Admin

2016-06-02 Thread Michal Petrucha
On Thu, Jun 02, 2016 at 07:22:16PM +1000, Mike Dewhirst wrote:
> I have a varchar field of 300+ chars and I'd like to know how to provide
> space to wrap it on screen without resorting to a TextField
> 
> Any CSS ideas?
> 
> Thanks
> 
> Mike

Perhaps you could override the widget to a Textarea with the right
maxlength attribute? That should be fine if you don't target IE<10...

Cheers,

Michal

-- 
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/20160602093101.GN29054%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


CSS question for the Admin

2016-06-02 Thread Mike Dewhirst
I have a varchar field of 300+ chars and I'd like to know how to provide 
space to wrap it on screen without resorting to a TextField


Any CSS ideas?

Thanks

Mike

--
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/b771dd58-8fdd-377d-a9ef-dda948359456%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9 - Create an app that use the models from another app and dynamic CBV

2016-06-02 Thread James Schneider
On Wed, Jun 1, 2016 at 5:21 AM,  wrote:

> I'm creating a basic CMS. The CMS will contain information about different
> Entities.
>
>
> A normal users can only see the information about the Entities but an
> editor will have access to an Dashboard were it can add new Entities or
> updated them.
>
> I have an app Entity that use class-based view (CBV) for
> create,update,details,list-display (CRUD).
>
You'll probably need to implement a permission system to control access to
resources.

>
> The urls for listing and details are: /entities and /entity-name
>
>
> Because update and create are behind login and use different urls I create
> a second app Dashboard that use the create/update models of the Entity app
>
One app can handle multiple URL schemes, both for anonymous and
authenticated requests simultaneously. You really only need multiple apps
when there is a clear separation of duties/functionality. They're really
more for organization of the code than any functional/technical reason.

>
> The urls are account/add and account/edit.
>
>
> *There is another solution to have different urls for views of the same
> model ?*
>
>
>
You can have as many views as you'd like for the same model. It is common
in situations where an object can be in different states at different
times. For example, an account is created for a user, so the user needs to
claim it, and then the new user needs to modify their own account with the
right details and change passwords, etc. That may also include having
multiple forms for the same object as well.

I want the fist page of the dashboard to show different information based
> on the following logic(exist and/or is activated):
>
>- if doesn't exist I want the CreateView (CBV) and corresponding form
>to appear
>- if exist but it is not active a Pending message
>- if exists and active the data of the entity
>
> I can do the logic at the template level, but to separate things is better
> to be done at the CBV level. So in this case I need some help, how to
> implement it.
>

Well, yes, and no. I wouldn't rely solely on the template to handle this
behavior. You'll be twisting yourself into a pretzel to make it work.
There's a couple of ways to make this work:

   - Have a single view that initially examines the situation, and then
   calls the respective functions or CBV's that handle the specific situation.
   Keeps the request logic within the view infrastructure, but not a typical
   strategy as far as I know. The same URL can then serve all of the
   situations.
   - Have a single view that builds a basic page structure, and use a JS
   framework and AJAX calls to build an SPA that displays the right
   information.
   - Have a separate view for each situation, along with a separate URL,
   and another view/URL for the main dashboard. Have the main dashboard view
   check for your logic, and redirect the browser to the URL for each action.
   Once the situation is corrected (form submitted, etc.) then redirect back
   to the main dashboard. This would be my preferred method.

You can use template inheritance in all of these situations to keep the
amount of template code down (which is generally advised since the template
system tends to be the slowest part of Django).

-James

-- 
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%2Be%2BciVf2DJ4NnVjcr9y%2B3SwS-T3eqS7vzEFVCnkfypJTE2D6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Views.py & queryset

2016-06-02 Thread James Schneider
On Wed, Jun 1, 2016 at 9:44 AM, Franck  wrote:

> Hello,
>
> Sorry first project...
>
> I can run :
> *Test.objects.filter(dateregister__contains='2016').count()in
> manage.py shell, result is ok.*In template, *{{ test.count }} *works
> well, but I tried *{{ *test.filter(dateregister__contains='2016').count()*
> }} *without success.
>
> *I can't use queryset directly in the template ?  (need to modify views.py
> ?)*
>

In most cases, you can't (and don't want to) use a queryset directly in the
template. That type of logic usually ends up in the view. The view is
responsible for preparing the data, whereas the template is responsible for
formatting the data provided by the view.

The reason that {{ test.count }} works is because you are storing a
queryset in the context, rather than the actual object (or list of objects
in this case). There are perfectly valid use cases for doing so, but keep
in mind there is a difference between a queryset and an actual object or
list of objects. If you use a queryset, you'll incur a database hit every
time you refer to that variable in the template, which is likely not what
you want. A notable exception is when looping over the queryset.

I'd recommend reading up on the template language and becoming familiar
with the (deliberate) restrictions on the template language:
https://docs.djangoproject.com/en/1.9/ref/templates/language/#variables

-James

-- 
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%2Be%2BciUid88r7be8sc2eGpNfcK7G-TWeDyhf3Fw7gE84%3DhsBCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Project Structure for mixins - best solution?

2016-06-02 Thread sevenrrainbow

Thank you Mike, I have a project related question also on this group, maybe 
you have time and take a look, please see the link below: 

Django Related Project Section 


-- 
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/96e53f40-6498-4097-a7d1-0a11b53beb71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Project Structure for mixins - best solution?

2016-06-02 Thread sevenrrainbow
Thank you Mike, I have a project related question also on this group, maybe 
you have time and take a look, please see the link below: 

Django Related Project Section 


On Thursday, June 2, 2016 at 2:42:43 AM UTC+3, Mike Dewhirst wrote:
>
> On 2/06/2016 12:54 AM, sevenr...@gmail.com  wrote: 
> > I seen multiple project structure for Django, but they didn't discuss in 
> > detail about structuring mixins. 
> > 
> > I see that some people use mixins.py , others utils folder. 
> > 
> > Taking in consideration that I have many mixins for views(generic 
> > login,authorization and more specific for the project) and for models 
> > and I don't know if using only 1 file mixins.py is the best solutions. 
> > 
> > So, I'm looking for recommendations, from projects with many mixins 
> > (views and models) ? 
>
> What works for me may not work for you. Just organise things the way you 
> feel comfortable. The bottom line is that if you use mixins they have to 
> be imported into the module where they are used. 
>
> That means ... 
>
> from overthere.mixins import thismixin 
>
> If you share mixins across a number of apps in the same project make an 
> extra app called "common" and make a directory mixins so ... 
>
> from common.mixins import thismixin 
>
> If you want to keep view and model mixins separate then ... 
>
> from common.views.mixins import thismixin 
>
> or 
>
> from app.views.mixins import thismixin 
>
> or 
>
> from . import thisviewmixin 
> from . import thismodelmixin 
>
> And so on. Make up a structure which suits your brain productivity-wise 
> so you don't have to think about where you are importing from and you 
> can go straight there without thinking when you want to edit them. 
>
> Practicality beats purity 
>
> > 
> > -- 
> > 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/0f1259db-17e2-4d5a-96cb-cf28e97fed96%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/0f1259db-17e2-4d5a-96cb-cf28e97fed96%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
> > 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/69aa069a-68d1-4d7a-afa6-f2cfc61ffee9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model inheritance with constraints

2016-06-02 Thread James Schneider
On Wed, Jun 1, 2016 at 12:45 PM, Arnab Banerji  wrote:

> Nevermind my last comment on this thread, when I refactored my existing
> model into an abstract base class with overrides, and then ran
> "makemigrations", Django said "no changed detected", so it is merely
> treated as a code refactor and not a database related change.
>
>
Yep, that was the whole intention of using the abstract classes. Glad it
worked out for you.

-James

-- 
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%2Be%2BciWK_SrqZCtjB7BxCqByrEcMWWoLx7oE3oOZHwtiQdN_VQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.